Module Module1

    Sub Main()

        Dim tmp As String() = Split(Console.ReadLine(), " ")
        Dim V As Integer = CInt(tmp(0))
        Dim E As Integer = CInt(tmp(1))
        Dim Map As New List(Of Grph)

        For i = 0 To E - 1
            Map.Add(New Grph(Console.ReadLine()))
        Next

        Dim Tmax = Console.ReadLine()
        Dim Odr As New List(Of Haccyu)

        For i = 0 To Tmax - 1

            Dim j As Integer = Console.ReadLine()
            For k = j To 1 Step -1
                Odr.Add(New Haccyu(i, j, k, Console.ReadLine()))
            Next
        Next

        For i = 0 To Tmax - 1
            Console.WriteLine(-1)
        Next

    End Sub

    Class Grph

        Private _StartPoint As Integer
        Private _EndPoint As Integer
        Private _Distance As Integer

        Sub New(inText As String)

            Dim tmp As String()

            tmp = Split(inText, " ")
            _StartPoint = CInt(tmp(0))
            _EndPoint = CInt(tmp(1))
            _Distance = CInt(tmp(2))

        End Sub

    End Class

    Class Haccyu
        Private _Timing As Integer
        Private _Hacyusu As Integer
        Private _Banme As Integer
        Private _OrderID As Integer
        Private _Cyoten As Integer

        Sub New(Timing As Integer, Hacyusu As Integer, Banme As Integer, Order As String)

            Dim tmp As String()

            tmp = Split(Order, " ")
            _Timing = Timing
            _Hacyusu = Hacyusu
            _OrderID = CInt(tmp(0))
            _Cyoten = CInt(tmp(1))

        End Sub
    End Class

End Module
