------
## 最终结论
To solve the problem optimally, we need to divide the array into two subarrays such that the sum of pairs equal to the unlucky integer \( T \) is minimized. Here's the Python code to achieve this:

```python
def solve():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    index = 0
    t = int(data[index])
    index += 1
    
    results = []
    
    for _ in range(t):
        n, T = int(data[index]), int(data[index + 1])
        index += 2
        
        a = list(map(int, data[index:index + n]))
        index += n
        
        color_map = {}
        
        for i in range(n):
            if a[i] not in color_map:
                color_map[a[i]] = 0
        
        result = [0] * n
        
        for i in range(n):
            complement = T - a[i]
            if complement in color_map:
                if color_map[complement] == 0:
                    result[i] = 1
                    color_map[a[i]] ^= 1
                else:
                    result[i] = 0
                    color_map[a[i]] ^= 1

        results.append(" ".join(map(str, result)))
    
    print("\n".join(results))

solve()
```

### Explanation

1. **Reading Input:**
   - We read all input data at once and split it into manageable parts using `split()`.
   - We process each test case by extracting `n` (number of elements) and `T` (unlucky integer).

2. **Initialize Data Structures:**
   - We use a dictionary `color_map` to track occurrences of numbers and their assigned colors.

3. **Processing Each Element:**
   - For each element `a[i]`, we calculate its complement with respect to `T` as `T - a[i]`.
   - If the complement exists in our map (`color_map`), we check its current "color" (0 or 1).
   - We alternate colors between pairs to ensure minimal misfortune.

4. **Output Results:**
   - After processing each test case, we store the result (a sequence of colors) and print it after processing all test cases.

The solution efficiently assigns colors to minimize pairs whose sum equals \( T \), using a greedy strategy with bitwise operations to toggle colors. This approach ensures that each element is processed in constant time, making it suitable for large inputs.