TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Once upon the time, there was a famous magical octopus which incredibly precisely predicted all the teams winning the golden cup. The golden cup was so lovely and so beautiful such that the loser teams really disliked octopuses. To protect this magical octopus, the king decided to add some locks outside the aquarium. Only a few people could get close to the octopus, and they must enter a corresponding password to unlock the aquarium. This password is a sequence of digits. Some of the guards wrote them down onto a little piece of paper, reminding them because they always forgot almost everything. For safety and security, the guards decided to add some leading and trailing digits to encrypting the password. But, there were still chances for them to forgot what the real password is. A mathematician -- he is one of the guards -- popped up with a good idea: he found that the password could be divided by some integer N when viewing this password as a decimal number. Moreover, in the encrypted string, the real password was exactly the substring that was divided by N when viewing as decimal and was the longest one over all such substrings. In addition, if there were several longest such substrings, the origional password was the first substring occured. Moreover, because 10 is the base of a decimal number, the mathematician chose the integer N be a relatively prime to 10, that is, N would never ever have prime factor 2 or 5. He then wrote down the number N and they were all satisfied with this idea.


Thousands years passed, in the world cup 2010, you suddenly get a little piece of paper filled with a sequence of digits, and an integer N. It seems that by decrypting the password you'll know which team would win. So, try it, why not?


(This is just a story, don't be too serious, please.)

Input Format

The first line contains an integer T<=50 indicating the number of test cases. For each test case, there are a string S and a positive integer N in a line. The string S is composed of only digits from 0' to9'. The length of S is no more than 100000 and the number N is no more than 100000. It is guaranteed that N is a relatively prime to ten, and there is always a solution.

Output Format

Please find out the origional passwords, and print them one per line.

Sample Input 1

3
123123123123 3
21198905143366 23291
10000210000000000000000000000000000000000000001000000 7

Sample Output 1

123123123123
19890514
000021000000000000000000000000000000000000000

Hints

How do you translate the following sentence into old-style chinese, "The golden cup was so lovely and so beautiful"?

Problem Source

Migrated from old NTUJ.

Tmt

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 8192