Roy and Wobbly Numbers : HackerEarth Problem Solution

Roy is looking for Wobbly Numbers.
An NN-length wobbly number is of the form "ababababab..." and so on of length NN, where a!=ba!=b.



A 3-length wobbly number would be of form "aba".
Eg: 101,121,131,252,646101,121,131,252,646 etc
But 111,222,999111,222,999 etc are not 33-length wobbly number, because here a!=ba!=b condition is not satisfied.
Also 010010 is not a 33-length wobbly number because it has preceding 00. So 010010 equals 1010 and 1010 is not a 33-length wobbly number.

A 44-length wobbly number would be of form "abab".

Eg: 2323,3232,9090,14142323,3232,9090,1414 etc


Similarly we can form a list of NN-length wobbly numbers.
Now your task is to find KKthth wobbly number from a lexicographically sorted list of NN-length wobbly numbers. If the number does not exist print −1−1 else print the KKtth wobbly number. See the sample test case and explanation for more clarity.

Input:

First line contains TT - number of test cases
Each of the next TT lines contains two space separated integers - NN and K

Output:

For each test case print the required output in a new line.

Sample Input:


6

3 1
3 2
3 100
4 3
4 4
5 2

Sample Output:


101

121
-1
1313
1414
12121

Explanation


First 10 terms of 3-length wobbly numbers arranged lexicographically is as follows: 101,121,131,141,151,161,171,181,191,202


1st wobbly number of length 3 is 101101. 2nd wobbly number of length 3 is 121. 100th wobbly number of length 3 does not exist, so the output is −1−1.

First 10 terms of 4-length wobbly numbers arranged lexicographically is as follows: 1010,1212,1313,1414,1515,1616,1717,1818,1919,2020


3rd wobbly number of length 4 is 1313. 4th wobbly number of length 4 is 1414.


Similarly 2nd wobbly number of length 5 is 12121


Implementation:


#include <stdio.h>

int main()
{
    int t;
    int n,k,a,b,x,i;
    scanf("%d",&t);
    while(t--)
    {
     scanf("%d %d",&n,&k);
     if(k>81)
      printf("-1\n");
     else
     {
      a=ceil((double)k/9.0);
      x=k-9*(a-1);
      b=x<=a?x-1:x;
      for(i=0;i<n;i++)
      {
       if(!(i&1))
        printf("%d",a);
       else
        printf("%d",b);
      }
      printf("\n");
     }
    }
    return 0;
}