------
## 最终结论
```python
import sys

def read_input():
    input = sys.stdin.read
    data = input().split()
    return data

def process_test_cases(data):
    index = 0
    T = int(data[index])
    index += 1
    
    results = []
    
    for _ in range(T):
        n = int(data[index])
        index += 1
        
        segments = []
        for i in range(n):
            l, r = int(data[index]), int(data[index + 1])
            segments.append((l, r, i))
            index += 2
        
        # Sort segments by their starting point (l), and by ending point (r) if starting points are equal
        segments.sort()
        
        # Determine the maximum right endpoint of the first group
        max_r1 = segments[0][1]
        
        # Find a split point where the next segment starts after max_r1
        split_found = False
        for i in range(1, n):
            if segments[i][0] > max_r1:
                split_found = True
                break
            max_r1 = max(max_r1, segments[i][1])
        
        if not split_found:
            results.append("-1")
        else:
            result = ["1"] * n
            for j in range(i, n):
                result[segments[j][2]] = "2"
            results.append(" ".join(result))
    
    return results

def main():
    data = read_input()
    results = process_test_cases(data)
    sys.stdout.write("\n".join(results) + "\n")

if __name__ == "__main__":
    main()
```

This code processes multiple test cases where each test case consists of several segments. The goal is to divide these segments into two non-empty groups such that no segment from one group intersects with any segment from the other group. If it is impossible to do so, it returns `-1` for that test case. The solution involves sorting the segments and finding a valid split point where the next segment starts after the maximum right endpoint of the current group. If such a split is found, it assigns groups accordingly; otherwise, it declares it impossible.