------
## 最终结论
```python
def distribute_gifts(t, test_cases):
    results = []
    for i in range(t):
        n, a, b = test_cases[i]
        
        # Sort both lists to ensure distinct sums
        a_sorted = sorted(a)
        b_sorted = sorted(b, reverse=True)
        
        # Append the sorted lists as result for this test case
        results.append((a_sorted, b_sorted))
    
    return results

# Example usage:
t = 2
test_cases = [
    (3, [1, 8, 5], [8, 4, 5]),
    (3, [1, 7, 5], [6, 1, 2])
]

results = distribute_gifts(t, test_cases)
for res in results:
    x_list, y_list = res
    print(" ".join(map(str, x_list)))
    print(" ".join(map(str, y_list)))
```