# Arup Guha
# 4/10/2026
# Solution to COP 4516 Problem: Who Stole My Burrito?

nC = int(input())

for loop in range(nC):

    toks = input().split()
    totalC = int(toks[0])
    totalS = int(toks[1])
    n = int(toks[2])

    # Do everyone else.
    for i in range(n-1):

        # Get input.
        toks = input().split()
        c = int(toks[0])
        s = int(toks[1])

        # Update what's left.
        totalC = max(totalC-c, 0)
        totalS = max(totalS-s, 0)

    # Get what I want.
    toks = input().split()
    cWant = int(toks[0])
    sWant = int(toks[1])

    # Here is what I get, the minimum of what I want and what's left.
    print(min(totalC,cWant), min(totalS,sWant))
        
