#P11280. 「GFOI Round 2」Jom & Terry

「GFOI Round 2」Jom & Terry

Description

Terry and Jom are playing a game on an undirected connected graph with nn nodes and mm edges, which has a designated "root" node rr. The game follows these rules:

  • Terry moves first.
  • The two players take turns moving along the edges of the graph, with each move traversing one edge (or they can choose to "rest" and do nothing).
  • Terry cannot move to the node where Jom is currently located (Terry is only considered "caught" if he voluntarily moves to the same node as Jom; it is allowed for both to move to the same node uu within the same turn, as long as Terry goes there first).

Given qq queries, each specifying the starting positions aa and bb of Terry and Jom respectively, determine whether Terry can reach the root node rr.

Input Format

The first line contains three integers nn, mm, and rr, representing the number of nodes, the number of edges, and the index of the root, respectively.

The next mm lines each contain two integers (u,v)(u, v), representing an edge between nodes uu and vv (Note that there may contain multiple edges and self-loops).

The following line contains a single integer qq, representing the number of queries.

The next qq lines each contain two integers aa and bb, representing the starting positions of Terry and Jom, respectively.

Output Format

Since this is a warm-up problem, you should print I'm here! at the beginning.

For the ii-th line of the next qq lines, print Terry if Terry can reach the root in the ii-th query; otherwise, print Jom.

5 4 3
4 3
3 2
1 5
1 2
2
1 2
5 4
I'm here!
Jom
Jom
5 5 4
1 4
4 3
3 2
4 5
5 3
2
3 1
5 1
I'm here!
Terry
Terry

Hint

Subtasks and Constraints

Subtask ID n,m,qn, m, q \le Special Properties Score
00 10610^6 A 11
11 1010 No 99
22 10610^6 B 1515
33 C
44 No 6060
  • Special Property A: q=0q = 0.
  • Special Property B: The graph is a chain.
  • Special Property C: The graph is a star graph.

For all tests, it is guaranteed that:

  • 1n,m1061 \le n, m \le 10^6;
  • 0q1060 \le q \le 10^6;
  • 1r,u,v,a,bn1 \le r, u, v, a, b \le n;
  • The given graph is an undirected connected graph.