n, m = list(map(int, input().split()))

r = [0]*n

r[0] = 1

c = [1]*n

for _ in range(m):

  x, y = list(map(int, input().split()))

  x -= 1

  y -= 1

  if r[x]:

    if c[x] == 1:

      r[x] = 0

    r[y] = 1

  c[x] -= 1

  c[y] += 1

print((r.count(1)))
n, m = list(map(int, input().split()))

C = [0]*(n+1)

C[1] = 1

D = [1]*(n+1)

for _ in range(m):

  x, y = list(map(int, input().split()))

  if C[x]:

    C[y] = 1

    if D[x] == 1:

      C[x] = 0

  D[x] -= 1

  D[y] += 1

ans = sum(C)

print(ans)
n, m = list(map(int, input().split()))
r = [0] * n
r[0] = 1
c = [1] * n
for _ in range(m):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    if r[x]:
        if c[x] == 1:
            r[x] = 0
        r[y] = 1
    c[x] -= 1
    c[y] += 1
print((r.count(1)))

n, m = list(map(int, input().split()))
C = [0] * (n + 1)
C[1] = 1
D = [1] * (n + 1)
for _ in range(m):
    x, y = list(map(int, input().split()))
    if C[x]:
        C[y] = 1
        if D[x] == 1:
            C[x] = 0
    D[x] -= 1
    D[y] += 1
ans = sum(C)
print(ans)

-r = [0] * n -r[0] = 1 -c = [1] * n +C = [0] * (n + 1) +C[1] = 1 +D = [1] * (n + 1) -    x -= 1 -    y -= 1 -    if r[x]: -        if c[x] == 1: -            r[x] = 0 -        r[y] = 1 -    c[x] -= 1 -    c[y] += 1 -print((r.count(1))) +    if C[x]: +        C[y] = 1 +        if D[x] == 1: +            C[x] = 0 +    D[x] -= 1 +    D[y] += 1 +ans = sum(C) +print(ans)