def main():
n = int(input())
for _ in range(n):
x = int(input())
y = int(input())
if(x==y):
print(y)
print(x)
continue
max_, min_ = max(x, y), min(x, y)
x_s, y_s = str(max_), str(min_)
x_l, y_l = max_, min_
j = len(x_s) - 1
while x_l > y_l:
if int(x_s[j]) > int(y_s[j]):
temp = x_s[j]
x_s = x_s[:j] + y_s[j] + x_s[j+1:]
y_s = y_s[:j] + temp + y_s[j+1:]
x_l, y_l = int(x_s), int(y_s)
j -= 1
j=j+1
temp = x_s[j]
x_s = x_s[:j] + y_s[j] + x_s[j+1:]
y_s = y_s[:j] + temp + y_s[j+1:]
x_l, y_l = int(x_s), int(y_s)
print(x_l)
print(y_l)
if __name__ == "__main__":
main()
102. Binary Tree Level Order Traversal | 96. Unique Binary Search Trees |
75. Sort Colors | 74. Search a 2D Matrix |
71. Simplify Path | 62. Unique Paths |
50. Pow(x, n) | 43. Multiply Strings |
34. Find First and Last Position of Element in Sorted Array | 33. Search in Rotated Sorted Array |
17. Letter Combinations of a Phone Number | 5. Longest Palindromic Substring |
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |