N, M = list(map(int, input().split()))

y_if = {1}

num = [1] * N

for i in range(M):

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

    num[x - 1] -= 1

    num[y - 1] += 1

    if x in y_if:

        if num[x - 1] == 0:

            y_if.remove(x)

        y_if.add(y)

print((len(y_if)))

N, M = list(map(int, input().split()))

ball = [1] * N

red = {1}

ans = 0

for _ in range(M):

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

    ball[x - 1] -= 1

    ball[y - 1] += 1

    if x in red:

        red.add(y)

        if ball[x - 1] == 0:

            red.remove(x)

print((len(red)))

N, M = list(map(int, input().split()))
y_if = {1}
num = [1] * N
for i in range(M):
    x, y = list(map(int, input().split()))
    num[x - 1] -= 1
    num[y - 1] += 1
    if x in y_if:
        if num[x - 1] == 0:
            y_if.remove(x)
        y_if.add(y)
print((len(y_if)))

N, M = list(map(int, input().split()))
ball = [1] * N
red = {1}
ans = 0
for _ in range(M):
    x, y = list(map(int, input().split()))
    ball[x - 1] -= 1
    ball[y - 1] += 1
    if x in red:
        red.add(y)
        if ball[x - 1] == 0:
            red.remove(x)
print((len(red)))

-y_if = {1} -num = [1] * N -for i in range(M): +ball = [1] * N +red = {1} +ans = 0 +for _ in range(M): -    num[x - 1] -= 1 -    num[y - 1] += 1 -    if x in y_if: -        if num[x - 1] == 0: -            y_if.remove(x) -        y_if.add(y) -print((len(y_if))) +    ball[x - 1] -= 1 +    ball[y - 1] += 1 +    if x in red: +        red.add(y) +        if ball[x - 1] == 0: +            red.remove(x) +print((len(red)))