This page is still under construction.

Parts of this page are still being built. What you see may change.

A Simple Sequence of Digits

Time limit1sMemory limit512 MB

Summary
Given n and k, build the digit string formed by concatenating the first n primes, then delete exactly k digits to leave the largest possible number.
Level

Medium5 of 10

Topics
Greedy, Stack, Number theory, Implementation
Solved
No attempts yet

Problem

During the break before math class, Roma decided to practice deciding whether a number is prime. Recall that a prime is a natural number with exactly two distinct natural divisors: one and itself. First he wrote the first prime on the board, then appended the second prime to its right, then the third, and so on. In total Roma wrote the first nn primes on the board. His work left a single long number on the board, which begins as <<23571113171923\dots>>.

When Yelena Yevgenyevna, Roma's teacher, entered the classroom, she gave the class the following task: cross out kk digits from the number on the board so that the remaining number is as large as possible.

Help Roma and his classmates solve the task, so that the strict teacher does not give them a failing grade.

Input

The input file for this problem contains several test cases. The first line of the input file contains the number TT, the number of test cases in the file.

The next TT lines describe the test cases, each consisting of two positive integers nn and kk. It is guaranteed that the first nn primes contain at least k+1k + 1 digits in total.

The sum of all nn in the input file does not exceed 400000.

Output

For each test case, output the required maximum number for the corresponding nn and kk on a separate line.

Hint

In the first test, Roma wrote the number 2357. The largest number that can be obtained by crossing out two digits from it is 57.

In the second test, Roma wrote the number 235711. The largest number that can be obtained by crossing out three digits from it is 711.

Examples1

  1. Example 1

    Input
    2
    4 2
    5 3
    
    Expected output
    57
    711