about summary refs log tree commit diff
path: root/codechef/chdiger.py
blob: a3c83fb8412783f58ba3b8b0fb8185006b144a03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3
for _ in range(int(input())):
    n, d = input().split()
    n, d = [int(x) for x in n], int(d)
    for i in range(-1, -1-len(n), -1):
        if n[i] > d:
            n[i] = d
        else:
            break
    for i in range(i, -len(n), -1):
        if n[i] < n[i-1]:
            n.pop(i - 1)
            n.append(d)
    print(''.join(map(str, n)))