# Acceptance of input

import sys



file_input = sys.stdin



V, E = list(map(int, file_input.readline().split()))



adj = [[] for i in range(V)]



for i in range(E):

    s, t = list(map(int, file_input.readline().split()))

    adj[s].append(t)



# Tarjan's strongly connected components algorithm(repetition)

import collections



S = collections.deque()

path = collections.deque()

index = 0

indices = [None] * V

lowlink = [None] * V

onStack = [False] * V

scc_id = [None] * V

parent = [0] * V



for v in range(V):

    if not indices[v]:

        index += 1

        indices[v] = index

        lowlink[v] = index

        S.append(v)

        path.append(v)

        onStack[v] = True



        while path:

            s = path[-1]

            adj_v = adj[s]

            for t in adj_v:

                if not indices[t]:

                    parent[t] = s

                    path.append(t)

                    S.append(t)

                    index += 1

                    indices[t] = index

                    lowlink[t] = index

                    onStack[t] = True

                    break

            if s == path[-1]:

                for t in adj_v:

                    if onStack[t]:

                        lowlink[s] = min(lowlink[s], lowlink[t])

                p = parent[s]

                lowlink[p] = min(lowlink[p], lowlink[s])

                if indices[s] == lowlink[s]:

                    while S:

                        w = S.pop()

                        onStack[w] =False

                        scc_id[w] = s

                        if w == s:

                            break

                path.pop()





# Output

Q = file_input.readline()



for line in file_input:

    u, v = list(map(int, line.split()))

    if scc_id[u] == scc_id[v]:

        print((1))

    else:

        print((0))
# Acceptance of input

import sys



file_input = sys.stdin



V, E = list(map(int, file_input.readline().split()))



adj = [[] for i in range(V)]



for i in range(E):

    s, t = list(map(int, file_input.readline().split()))

    adj[s].append(t)



# Tarjan's strongly connected components algorithm(repetition)

import collections



S = collections.deque()

path = collections.deque()

index = 0

indices = [None] * V

lowlink = [None] * V

onStack = [False] * V

scc_id = [None] * V

parent = [0] * V



for v in range(V):

    if not indices[v]:

        index += 1

        indices[v] = index

        lowlink[v] = index

        S.append(v)

        path.append(v)

        onStack[v] = True



        while path:

            s = path[-1]

            adj_v = adj[s]

            for t in adj_v:

                if not indices[t]:

                    parent[t] = s

                    path.append(t)

                    S.append(t)

                    index += 1

                    indices[t] = index

                    lowlink[t] = index

                    onStack[t] = True

                    adj_v.remove(t)

                    break

            if s == path[-1]:

                for t in adj_v:

                    if onStack[t]:

                        lowlink[s] = min(lowlink[s], lowlink[t])

                p = parent[s]

                lowlink[p] = min(lowlink[p], lowlink[s])

                if indices[s] == lowlink[s]:

                    while S:

                        w = S.pop()

                        onStack[w] =False

                        scc_id[w] = s

                        if w == s:

                            break

                path.pop()





# Output

Q = file_input.readline()



for line in file_input:

    u, v = list(map(int, line.split()))

    if scc_id[u] == scc_id[v]:

        print((1))

    else:

        print((0))
# Acceptance of input
import sys

file_input = sys.stdin
V, E = list(map(int, file_input.readline().split()))
adj = [[] for i in range(V)]
for i in range(E):
    s, t = list(map(int, file_input.readline().split()))
    adj[s].append(t)
# Tarjan's strongly connected components algorithm(repetition)
import collections

S = collections.deque()
path = collections.deque()
index = 0
indices = [None] * V
lowlink = [None] * V
onStack = [False] * V
scc_id = [None] * V
parent = [0] * V
for v in range(V):
    if not indices[v]:
        index += 1
        indices[v] = index
        lowlink[v] = index
        S.append(v)
        path.append(v)
        onStack[v] = True
        while path:
            s = path[-1]
            adj_v = adj[s]
            for t in adj_v:
                if not indices[t]:
                    parent[t] = s
                    path.append(t)
                    S.append(t)
                    index += 1
                    indices[t] = index
                    lowlink[t] = index
                    onStack[t] = True
                    break
            if s == path[-1]:
                for t in adj_v:
                    if onStack[t]:
                        lowlink[s] = min(lowlink[s], lowlink[t])
                p = parent[s]
                lowlink[p] = min(lowlink[p], lowlink[s])
                if indices[s] == lowlink[s]:
                    while S:
                        w = S.pop()
                        onStack[w] = False
                        scc_id[w] = s
                        if w == s:
                            break
                path.pop()
# Output
Q = file_input.readline()
for line in file_input:
    u, v = list(map(int, line.split()))
    if scc_id[u] == scc_id[v]:
        print((1))
    else:
        print((0))

# Acceptance of input
import sys

file_input = sys.stdin
V, E = list(map(int, file_input.readline().split()))
adj = [[] for i in range(V)]
for i in range(E):
    s, t = list(map(int, file_input.readline().split()))
    adj[s].append(t)
# Tarjan's strongly connected components algorithm(repetition)
import collections

S = collections.deque()
path = collections.deque()
index = 0
indices = [None] * V
lowlink = [None] * V
onStack = [False] * V
scc_id = [None] * V
parent = [0] * V
for v in range(V):
    if not indices[v]:
        index += 1
        indices[v] = index
        lowlink[v] = index
        S.append(v)
        path.append(v)
        onStack[v] = True
        while path:
            s = path[-1]
            adj_v = adj[s]
            for t in adj_v:
                if not indices[t]:
                    parent[t] = s
                    path.append(t)
                    S.append(t)
                    index += 1
                    indices[t] = index
                    lowlink[t] = index
                    onStack[t] = True
                    adj_v.remove(t)
                    break
            if s == path[-1]:
                for t in adj_v:
                    if onStack[t]:
                        lowlink[s] = min(lowlink[s], lowlink[t])
                p = parent[s]
                lowlink[p] = min(lowlink[p], lowlink[s])
                if indices[s] == lowlink[s]:
                    while S:
                        w = S.pop()
                        onStack[w] = False
                        scc_id[w] = s
                        if w == s:
                            break
                path.pop()
# Output
Q = file_input.readline()
for line in file_input:
    u, v = list(map(int, line.split()))
    if scc_id[u] == scc_id[v]:
        print((1))
    else:
        print((0))

+                    adj_v.remove(t)