Big Integer

0

0 votes
Problem

Problem Statement :

Given an integer N, permute its digits in such a way such that the absolute difference between the resulting number and N is maximum and the difference is divisible by 9.

 

Input Format :

  • The first line contains T, the number of testcases.
  • Each of the next T lines contain a single integer N.

 

Output Format :

  • Print line separated outputs, in each line a single integer denoting the absolute difference between N and the permuted number.

 

Constraints :

  • 1N<1018
  • 1T1000
Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

123 can be permuted to 321 to the get the maximum number divisible by 9 ie. 321 - 123 = 198.

Editor Image

?