QOJ.ac

QOJ

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓

#15032. Cipher

İstatistikler

Alice designed a cipher system: it encodes the plaintext as a 64-bit unsigned integer $x$, and randomly selects a 64-bit unsigned integer $a$ as the public key, encrypting the plaintext to get ciphertext $b = a^x \bmod 2^{64}$. In particular, it is defined that $0^0 = 1$.

Now, Bob has intercepted $n$ sets of encrypted information $(a_i, b_i)$ ($i = 1, 2, \dots, n$). To decrypt all the information, Bob needs to find the smallest integer $x_i$ ($0 \le x_i < 2^{64}$) for each set of encrypted information such that $a_i^{x_i} \equiv b_i \pmod{2^{64}}$, or determine that the information has been corrupted (i.e., there is no $x_i$ that satisfies the condition). Please write a program to help Bob accomplish this task.

Input

The first line of input contains an integer $n$ ($1 \le n \le 10^5$), representing the number of messages.

The next $n$ lines, the $i$-th line contains two integers $a_i$ and $b_i$ ($0 \le a_i, b_i < 2^{64}$), representing the public key and ciphertext of the $i$-th set of information, respectively.

Output

Output $n$ lines, for the $i$-th line:

  • If there exists at least one $x_i$ that satisfies the conditions stated in the problem, output the smallest one;
  • Otherwise, output a line broken message.

Example

Input

5
2 4
3 27
1000000007 998244353
4 2
1000000007 1000000009

Output

2
3
994996658310742016
broken message
broken message

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#3008EditorialOpen题解KobicGendView
#904EditorialOpenNew Editorial for Problem #15032KiharaToumaView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.