def main():
    h = CodeJamHelper("C-small-attempt2")    
    
    n = h.nextInt()

    for x in range(n):
        h.output(process(h.nextLineOfInts()))
def main():
    h = CodeJamHelper("A-large")    
    
    t = h.nextInt()

    for x in range(t):
        h.output(process(h.nextDelimitedLine("/")))
def main():
    h = CodeJamHelper("B-large-practice")    
    
    n = h.nextInt()

    for x in range(n):
        h.output(process(h.nextDelimitedLine()))
def main():
    h = CodeJamHelper("A-large-practice")    
    
    t = h.nextInt()

    for x in range(t):
        case = h.nextLineOfInts(" ")
        h.output(process(case[0], case[1]))
def main():
    h = CodeJamHelper("B-sample")    
    
    t = h.nextInt()
    for x in range(t):
        abk = h.nextLineOfInts()
        a = abk[0]
        b = abk[1]
        k = abk[2]
        h.output(process(a,b,k))
def main():
    h = CodeJamHelper("C-large-practice")    
    
    t = h.nextInt()

    for x in range(t):
        params = h.nextLineOfInts(" ")
        groups = h.nextLineOfInts(" ")
        if len(groups) != params[2]:
            print "problem"
        h.output(process(params[0], params[1], groups))
def main():
    h = CodeJamHelper("A-large-practice")    
    
    n = h.nextInt()

    for x in range(n):
        h.output(process(h.nextInt(), h.nextLineOfInts(), h.nextLineOfInts()))
def main():
    h = CodeJamHelper("A-small-attempt1")    
    
    t = h.nextInt()
    for x in range(t):
        n = h.nextInt()
        strs = []
        for y in range(n):
            strs.append(h.nextLine())
        h.output(process(strs))
def main():
    h = CodeJamHelper("A-small-attempt0")    
    
    t = h.nextInt()

    for x in range(t):
        nt = h.nextLineOfInts()
        n = nt[0]
        t = nt[1]
        flows = h.nextDelimitedLine()
        flows = [[y == "1" for y in flow] for flow in flows ]
        devices = h.nextDelimitedLine()
        devices = [[y == "1" for y in device] for device in devices]
        h.output(process(flows, devices))
def main():
    h = CodeJamHelper("A-large-practice")    
    
    n = h.nextInt()

    for x in range(n):
        pkl = h.nextLineOfInts()
        p = pkl[0]
        k = pkl[1]
        l = pkl[2]
        freq = h.nextLineOfInts()
        h.output(process(p, k , l , freq))
def main():
    h = CodeJamHelper("A-large-practice")    
    
    n = h.nextInt()

    for x in range(n):
        nFlavors = h.nextInt()
        nCustomers = h.nextInt()
        customers = []
        for c in range(nCustomers):
            cValues = h.nextLineOfInts()
            if cValues[0] != (len(cValues)-1)/2:
                print "problem, incorrect number of shake preferences"
            customers.append(cValues[:1])
        if len(customers) != nCustomers:
            print "problem, incorrect number of customers"
        h.output(process(nFlavors, customers))
def main():
    h = CodeJamHelper("C-sample")    
    
    t = h.nextInt()
    for x in range(t):
        nm = h.nextLineOfInts()
        n = nm[0]
        m = nm[1]
        zips = []
        flights = []
        for cities in range(n):
            zips.append(h.nextInt())
        for f in range(m):
            s = h.nextLineOfInts()
            flight = (s[0], s[1])
            flights.append(flight)
        h.output(process(zips, flights, h))