Helping Meesa
Submissions: 400   Accuracy:


  Difficulty: Easy   Marks: 2

A Lucky number is a number which has only the digits 4 and 7. Meesa makes a special function F(n) for a positive integer n  that returns all good digits of number n from the left to the right. For example, the the output for number 147 is number 47. Meesa has two numbers :

  • An integer a 
  • A Lucky number b.

Help Meesa to find the minimum number c (c > a) such that  F(c) = b.


The first line contain T denoting the number of Test cases. Then T test cases follow . Each test case has only line contains two integers a and bIt is guaranteed that number b is lucky.


Print the number in a new line  that Meesa needs to find.


1 ≤ T≤ 50

1 ≤ a, b ≤ 105

Sample Input:


1 7

Sample Output:



The minimum number x greater than 1 such that F(x) = 7 is 7 & so it is the answer.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Siddharth Dungarwal
Author: sd5869

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.