- All Contests
- ProjectEuler+
- Project Euler #111: Primes with runs

# Project Euler #111: Primes with runs

# Project Euler #111: Primes with runs

_{This problem is a programming version of Problem 111 from projecteuler.net}

Considering -digit primes containing repeated digits it is clear that they cannot all be the same: is divisible by , is divisible by , and so on. But there are nine -digit primes containing three ones: .

We shall say that represents the maximum number of repeated digits for an -digit prime where is the repeated digit; represents the number of such primes; and represents the set of these primes.

So is the maximum number of repeated digits for a -digit prime where one is the repeated digit, there are such primes, and . It turns out that for , it is only possible to have repeated digits, but there are such cases.

Determine the set for a given values of and .

**Input Format**

First line contains an integer denoting the number of test cases.

Each of the following lines contain two integers and .

**Constraints**

**Output Format**

For each of test cases print one line containing all primes that belong to in ascending order.

**Sample Input**

```
2
4 1
4 0
```

**Sample Output**

```
1117 1151 1171 1181 1511 1811 2111 4111 8111
1009 2003 3001 4001 4003 4007 5003 5009 6007 7001 8009 9001 9007
```