while True:
    a=[int(i) for i in input().split()]
    if a[0]==0:
        break

    like=[]
    dislike=[]
    pair=[]

    for i in range(a[1]):
        n=[int(i) for i in input().split()]
        like.append(n)

    for i in range(a[2]):
        n=[int(i) for i in input().split()]
        dislike.append(n)

    for i in range(int(a[0]/3)):
        n=[int(i) for i in input().split()]
        pair.append(n)

    ir=0

    for i in pair:
        for j in like:
            if j[0] in i:
                if j[1] not in i:
                    ir+=1
        for j in dislike:
            if j[0] in i and j[1] in i:
                ir+=1
    
    print(ir)