A. Tsunade's Luck

4.5

2 votes
Problem

Tsunade believes in lucky numbers,  A lucky number is one in which all digits are equal like 11, 222. Jiraya gives her a number and asks her to tell the minimum non-negative number x she should add so that a resulting number is a lucky number. Help Tsunade to find that number.

INPUT

The first line of the input contains the number of tests t (1t100).

Each test is described in one line. The first line contains one integer N — the number given by Jiraya.

0<= N <= 1017.

OUTPUT

An integer x (x>=0) i.e the minimum number that must be added to make N a lucky number.

Sample Input
2
10
311
Sample Output
1
22
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

11 is the nearest lucky number so we need to add 1 to 10 to make it a lucky number.333 is the nearest lucky number so we need to add 22 to 311 to make it a lucky number.

Contributers:
Editor Image

?