------
## 最终结论
```python
def reconstruct_w(t, test_cases):
    results = []
    for case in test_cases:
        s, x = case
        n = len(s)
        w = ['1'] * n

        # First pass to set '0's in w
        for i in range(n):
            if s[i] == '0':
                if i - x >= 0:
                    w[i - x] = '0'
                if i + x < n:
                    w[i + x] = '0'

        # Second pass to check if we can generate s from w
        valid = True
        for i in range(n):
            if s[i] == '1':
                if not ((i - x >= 0 and w[i - x] == '1') or (i + x < n and w[i + x] == '1')):
                    valid = False
                    break

        if valid:
            results.append(''.join(w))
        else:
            results.append('-1')

    return results

# Read input data
t = int(input().strip())
test_cases = []
for _ in range(t):
    s = input().strip()
    x = int(input().strip())
    test_cases.append((s, x))

# Process each test case and print the result
results = reconstruct_w(t, test_cases)
for result in results:
    print(result)
```