#P15499. [ICPC 2025 APC] Secret Lilies and Roses

[ICPC 2025 APC] Secret Lilies and Roses

Description

There are nn flowers arranged in a line from left to right, which are numbered from 11 to nn in that order. Each flower is either a lily or a rose. For an integer jj between 00 and nn, inclusive, let ljl_{j} denote the number of lilies among the leftmost jj flowers, and let rjr_{j} denote the number of roses among the rightmost njn - j flowers.

Initially, only the number of flowers nn is provided to you. The types of the flowers are hidden. You can obtain information on the flowers by making queries. In one query, you can perform one of the following.

Type query: Specify an integer ii between 11 and nn, inclusive. You will then receive the type of flower ii.

Multiply query: Specify an integer jj between 00 and nn, inclusive. You will then receive the value of lj×rjl_{j} \times r_{j}.

Your task is to find an integer kk between 00 and nn, inclusive, for which lk=rkl_{k} = r_{k} by making a limited number of queries. You can assume that at least one such integer exists for the arrangement of the flower types. Note that you do not need to identify the type of each flower.

Interaction

The first line of input contains one integer tt (1t1001 \leq t \leq 100) representing the number of test cases. After that, tt test cases follow. Each of them is presented as follows.

The first line of input for each test case contains an integer nn (1n1001 \leq n \leq 100). After reading it, your program can start making queries. For each query, your program should write a line containing one of the following:

  • "type ii" to perform a Type query by specifying an integer ii (1in1 \leq i \leq n). In response, an input line containing a string either lily or rose becomes available, indicating the type of flower ii.
  • "multi jj" to perform a Multiply query by specifying an integer jj (0jn0 \leq j \leq n). In response, an input line containing the integer lj×rjl_{j} \times r_{j} becomes available.

Your program is allowed to make up to 1010 queries for each test case. This means the total number of Type queries and Multiply queries combined must not exceed 1010. If your program makes more than 1010 queries, it will be judged as "Wrong Answer".

When your program identifies an integer kk such that lk=rkl_{k} = r_{k}, it should write a line of the form "answer kk" (0kn0 \leq k \leq n). Note that providing the answer does not count as a query.

The input guarantees that at least one correct output exists. If there are multiple correct outputs, any one of them will be accepted.

After writing the answer line, your program should start processing the next test case. When all tt test cases have been processed, the interaction stops and your program should terminate.

Notes on interactive judging:

  • The evaluation is non-adversarial, meaning that the types of the flowers are chosen in advance rather than in response to your queries.
  • Do not forget to flush output buffers after writing. See the "Judging Details" document for details.
  • You are provided with a command-line tool for local testing, together with input files corresponding to the sample interactions. You can download these files from DOMjudge. The tool has comments at the top to explain its use.
2
9

lily

rose

6

3

3

0

rose



type 8

type 1

multi 6

multi 3

answer 5

multi 3

type 3

answer 3

Hint

Explanation for the sample interaction #1

For the first test case, nine flowers are arranged as shown in the following figure. In response to the third query, l6×r6=3×2=6l_{6} \times r_{6} = 3 \times 2 = 6 is returned, and in response to the fourth query, l3×r3=1×3=3l_{3} \times r_{3} = 1 \times 3 = 3 is returned. Since l5=r5=3l_{5} = r_{5} = 3, k=5k = 5 is a correct output.

:::align{center} :::

For the second test case, all three flowers are assumed to be roses.