from collections import *

import sys



cnt1 = Counter()

cnt2 = Counter()

for s in sys.stdin:

    if s == "\n": break

    n,d = list(map(int,s.split(",")))

    cnt1[n] += 1

for s in sys.stdin:

    if s == "\n": break

    n,d = list(map(int,s.split(",")))

    cnt2[n] += 1

for e in cnt1:

    if cnt2[e]: print(e,cnt1[e]+cnt2[e])
from collections import *

import sys



cnt1 = Counter()

cnt2 = Counter()

for s in sys.stdin:

    if s == "\n": break

    cnt1[list(map(int,s.split(",")))[0]] += 1

for s in sys.stdin:

    if s == "\n": break

    cnt2[list(map(int,s.split(",")))[0]] += 1

for e in cnt1:

    if cnt2[e]: print(e,cnt1[e]+cnt2[e])
from collections import *
import sys

cnt1 = Counter()
cnt2 = Counter()
for s in sys.stdin:
    if s == "\n":
        break
    n, d = list(map(int, s.split(",")))
    cnt1[n] += 1
for s in sys.stdin:
    if s == "\n":
        break
    n, d = list(map(int, s.split(",")))
    cnt2[n] += 1
for e in cnt1:
    if cnt2[e]:
        print(e, cnt1[e] + cnt2[e])

from collections import *
import sys

cnt1 = Counter()
cnt2 = Counter()
for s in sys.stdin:
    if s == "\n":
        break
    cnt1[list(map(int, s.split(",")))[0]] += 1
for s in sys.stdin:
    if s == "\n":
        break
    cnt2[list(map(int, s.split(",")))[0]] += 1
for e in cnt1:
    if cnt2[e]:
        print(e, cnt1[e] + cnt2[e])

-    n, d = list(map(int, s.split(","))) -    cnt1[n] += 1 +    cnt1[list(map(int, s.split(",")))[0]] += 1 -    n, d = list(map(int, s.split(","))) -    cnt2[n] += 1 +    cnt2[list(map(int, s.split(",")))[0]] += 1