Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:

  if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1);  if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1);  if both of the aforementioned conditions are false, then $s_i$ is 0. 

You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).

The total length of all strings $s$ in the input does not exceed $10^5$.


-----Output-----

For each test case, print the answer on a separate line as follows:

  if no string $w$ can produce the string $s$ at the end of the process, print $-1$;  otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them. 


-----Example-----
Input
3
101110
2
01
1
110
1

Output
111011
10
-1

Difficulty: MEDIUM

Solutions:
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	x = int(input())
	ans = [1] * n
	check = True
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == 1 or (i + x < n and ans[i + x] == 1):
				continue
			check = False
			break
	if check:
		print(*ans, sep='')
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	w1 = '1' * len(s)
	w = list(w1)
	f = 0
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0 and i + x <= len(s) - 1:
				w[i - x] = '0'
				w[i + x] = '0'
			elif i - x < 0 and i + x <= len(s) - 1:
				w[i + x] = '0'
			elif i - x >= 0 and i + x > len(s) - 1:
				w[i - x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and i + x <= len(s) - 1:
				if w[i - x] == '0' and w[i + x] == '0':
					f = 1
			elif i - x < 0 and i + x <= len(s) - 1:
				if w[i + x] == '0':
					f = 1
			elif i - x >= 0 and i + x > len(s) - 1:
				if w[i - x] == '0':
					f = 1
			else:
				f = 1
	if f == 1:
		print(-1)
	else:
		print(''.join(w))


T = int(input())
for _ in range(T):
	w = input()
	x = int(input())
	n = len(w)
	l = ['1' for k in range(n)]
	for i in range(n):
		if w[i] == '0':
			if i - x >= 0:
				l[i - x] = '0'
			if i + x < n:
				l[i + x] = '0'
	flag = 0
	for i in range(n):
		if i + x < n and l[i + x] == '1':
			if w[i] == '0':
				flag += 1
		elif i - x >= 0 and l[i - x] == '1':
			if w[i] == '0':
				flag += 1
		elif w[i] == '1':
			flag += 1
	if flag != 0:
		print(-1)
	else:
		print(''.join(l))


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	l = z()
	n = len(l)
	x = int(z())
	li = ['1'] * n
	c = 0
	for i in range(n):
		if l[i] == '0':
			try:
				if i - x >= 0:
					li[i - x] = '0'
			except:
				pass
			try:
				li[i + x] = '0'
			except:
				pass
	for i in range(n):
		if l[i] == '1':
			try:
				if li[i - x] == '1' and i - x >= 0:
					continue
				elif li[i + x] == '1' and i + x < n:
					continue
				else:
					c = 1
					print(-1)
					break
			except:
				c = 1
				print(-1)
				break
	if c == 0:
		print(''.join(li))


t = int(input())
for _ in range(t):
	s = list(str(input()))
	x = int(input())
	w = ['1' for _ in range(len(s))]
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	flag = False
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and i + x < len(s):
				if w[i - x] == '0' and w[i + x] == '0':
					flag = True
			elif i - x >= 0 and i + x >= len(s):
				if w[i - x] == '0':
					flag = True
			elif i - x < 0 and i + x < len(s):
				if w[i + x] == '0':
					flag = True
			elif i - x < 0 and i + x >= len(s):
				flag = True
	if flag == True:
		print(-1)
	else:
		res = ''
		for i in range(len(w)):
			res += w[i]
		print(res)


t = int(input(''))
arr = []
x = []
for i in range(t):
	arr.append(input(''))
	x.append(int(input('')))
for i in range(t):
	s = list(arr[i])
	y = x[i]
	n = len(s)
	dp = ['1'] * n
	flag = 0
	for j in range(n):
		if s[j] == '0':
			if j - y >= 0:
				dp[j - y] = '0'
			if j + y < n:
				dp[j + y] = '0'
	sol = ''
	for j in range(n):
		flag = 0
		if j - y >= 0:
			if dp[j - y] == '1':
				flag = 1
		if j + y < n:
			if dp[j + y] == '1':
				flag = 1
		if flag:
			sol += '1'
		else:
			sol += '0'
	if s == list(sol):
		print(''.join(dp))
	else:
		print(-1)


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	n = len(s)
	l = ['2'] * n
	check = True
	for i in range(n):
		if s[i] == '1':
			if i - x < 0 and i + x < n:
				if l[i + x] == '0':
					check = False
				l[i + x] = '1'
			if i + x >= n and i - x >= 0:
				if l[i - x] == '0':
					check = False
				l[i - x] = '1'
		else:
			if i - x >= 0:
				if l[i - x] == '1':
					check = False
				l[i - x] = '0'
			if i + x < n:
				if l[i + x] == '1':
					check = False
				l[i + x] = '0'
	nat = -1
	if check == True:
		for i in range(n):
			if s[i] == '1':
				t = 0
				z = 0
				if i - x >= 0:
					z += 1
					if l[i - x] == '0':
						t += 1
				if i + x < n:
					z += 1
					if l[i + x] == '0':
						t += 1
				if t == z:
					check = False
		if check == True:
			nat = ''
			for i in range(n):
				if l[i] != '0':
					nat += '1'
				else:
					nat += '0'
	print(nat)


for _ in range(int(input())):
	s = input()
	x = int(input())
	ls = len(s)
	a = [1] * ls
	for (i, k) in enumerate(s):
		if k == '0':
			if i - x >= 0:
				a[i - x] = 0
			if i + x < ls:
				a[i + x] = 0
	for (i, k) in enumerate(s):
		if k == '1':
			f = 0
			if i - x >= 0:
				f |= a[i - x]
			if i + x < ls:
				f |= a[i + x]
			if not f:
				print(-1)
				break
	else:
		print(''.join((str(a) for a in a)))


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	w = [1] * len(s)
	for i in range(0, len(s)):
		if int(s[i]) == 0:
			if i - x >= 0:
				w[i - x] = 0
			if x + i < len(s):
				w[i + x] = 0
	for i in range(0, len(s)):
		if int(s[i]) == 1:
			sumation = 0
			if i - x >= 0:
				sumation += w[i - x]
			if x + i < len(s):
				sumation += w[i + x]
			if sumation < 1:
				print(-1)
				break
	else:
		print(''.join(map(str, w)))


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x > -1:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	imp = 0
	for i in range(n):
		if s[i] == '1':
			val = 0
			if i - x > -1 and ans[i - x] != '0':
				val += 1
			if i + x < n and ans[i + x] != '0':
				val += 1
			if val == 0:
				imp = 1
				break
		else:
			if i - x > -1 and ans[i - x] != '0':
				imp = 1
				break
			if i + x < n and ans[i + x] != '0':
				imp = 1
				break
	if imp == 1:
		print(-1)
	else:
		for i in ans:
			print(i, end='')
		print()


import math
t = int(input())
for q in range(t):
	s = input()
	x = int(input())
	w = [1] * len(s)
	t = True
	n = len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + 1 > x:
				w[i - x] = 0
			if n >= x + i + 1:
				w[i + x] = 0
	for i in range(len(s)):
		if s[i] == '1' and i + 1 <= x and (n < x + i + 1):
			t = False
			break
		if s[i] == '1' and i + 1 <= x and (n >= x + i + 1) and (w[i + x] == 0):
			t = False
			break
		if s[i] == '1' and i + 1 > x and (n < x + i + 1) and (w[i - x] == 0):
			t = False
			break
		if s[i] == '1' and i + 1 > x and (n >= x + i + 1) and (w[i - x] == 0) and (w[i + x] == 0):
			t = False
			break
	if t:
		for i in w:
			print(i, end='')
		print('')
	else:
		print(-1)


for _ in range(int(input())):
	data = list(map(int, list(input())))
	x = int(input())
	l = len(data)
	w = [0] * l
	for i in range(l):
		if i + x < l:
			w[i + x] += 1 if data[i] else -1
		if i - x > -1:
			w[i - x] += 1 if data[i] else -1
	ans = [0] * l
	for i in range(l):
		if w[i] > 0:
			ans[i] = 1
	rec = [0] * l
	for i in range(l):
		if i + x < l:
			rec[i] = rec[i] | ans[i + x]
		if i - x > -1:
			rec[i] = rec[i] | ans[i - x]
	if rec != data:
		print(-1)
	else:
		print(*ans, sep='')


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	s1 = [1] * n
	for i in range(n):
		if i >= x and w[i - x] == 1 or (i + x < n and w[i + x] == 1):
			s1[i] = 1
		else:
			s1[i] = 0
	w = ''.join([str(i) for i in w])
	s = ''.join([str(i) for i in s])
	s1 = ''.join([str(i) for i in s1])
	if s == s1:
		print(w)
	else:
		print(-1)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		flag = False
		n = len(s)
		x = int(input())
		w = [-1] * n
		for i in range(x):
			if i + x >= n:
				if s[i] == '0':
					continue
				else:
					flag = True
					break
			w[i + x] = int(s[i])
		if flag:
			print(-1)
			continue
		for i in range(x, n):
			if int(s[i]) == 1:
				if w[i - x] == 0:
					if i + x >= n:
						flag = True
						break
					else:
						w[i + x] = 1
				elif w[i - x] == -1:
					w[i - x] = 1
			else:
				if w[i - x] == 1:
					flag = True
					break
				if w[i - x] == -1:
					w[i - x] = 0
				if i + x < n:
					if w[i + x] == 1:
						flag = True
						break
					w[i + x] = 0
		if flag:
			print(-1)
			continue
		for i in range(n):
			if w[i] == -1:
				w[i] = 1
			print(w[i], end='')
		print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def s_of(w):
	ret = []
	for i in range(len(w)):
		anchors = []
		for j in [i - x, i + x]:
			if 0 <= j < len(w):
				anchors += [w[j]]
		if 1 in anchors:
			ret += [1]
		else:
			ret += [0]
	return ret

def ans(S, x):
	ret = [1] * len(S)
	for (i, s) in enumerate(S):
		if s == '0':
			for j in [i - x, i + x]:
				if 0 <= j < len(ret):
					ret[j] = 0
	if ''.join(map(str, s_of(ret))) == S:
		return ''.join(map(str, ret))
	else:
		return '-1'
T = int(input())
for t in range(T):
	S = input()
	x = int(input())
	print(ans(S, x))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().rstrip()
	x = int(input())
	n = len(s)
	ans = [1] * n
	for i in range(n):
		a = i + x
		b = i - x
		if s[i] == '0':
			if a > -1 and a < n:
				ans[a] = 0
			if b > -1 and b < n:
				ans[b] = 0
	ok = 1
	for i in range(n):
		a = i + x
		b = i - x
		tot = 0
		if a > -1 and a < n:
			if ans[a] == 1:
				tot += 1
			if ans[a] == 1 and s[i] == '0':
				ok = 0
				break
		if b > -1 and b < n:
			if ans[b] == 1:
				tot += 1
			if ans[b] == 1 and s[i] == '0':
				ok = 0
				break
		if s[i] == '1' and tot == 0:
			ok = 0
			break
	if ok == 1:
		print(''.join([str(x) for x in ans]))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	final = [1 for _ in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				final[i + x] = 0
			if i - x > -1:
				final[i - x] = 0
	done = 0
	for i in range(n):
		if s[i] == '1':
			if (i + x >= n or final[i + x] == 0) and (i - x < 0 or final[i - x] == 0):
				done = 1
				break
	print(*([-1], final)[not done], sep='')


import sys, math, cmath, time
start_time = time.time()

def solve():
	w = insr()
	x = inp()
	s = ['1'] * len(w)
	for i in range(len(w)):
		if i < x and i + x < len(w):
			if w[i] == '0':
				s[i + x] = '0'
		elif i >= len(w) - x and i - x >= 0:
			if w[i] == '0':
				s[i - x] = '0'
		elif i + x < len(w) and i - x >= 0 and (w[i] == '0'):
			s[i + x] = '0'
			s[i - x] = '0'
	ww = w
	w = ''.join(s)
	s = ['0'] * len(w)
	for i in range(len(w)):
		if i < x and i + x < len(w):
			if w[i + x] == '1':
				s[i] = '1'
		elif i >= len(w) - x and i - x >= 0:
			if w[i - x] == '1':
				s[i] = '1'
		elif i + x < len(w) and i - x >= 0 and (w[i + x] == '1' or w[i - x] == '1'):
			s[i] = '1'
	if ''.join(s) == ww:
		print(w)
	else:
		print(-1)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * 100
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def findEncoded(s, x):
	enc = list(['0'] * len(s))
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0:
				enc[i - x] = '1'
			if i + x < len(s):
				enc[i + x] = '1'
	return enc

def findOriginal(s, x):
	orig = list(['1'] * len(s))
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				orig[i - x] = '0'
			if i + x < len(s):
				orig[i + x] = '0'
	return orig
for _ in range(int(input())):
	s = list(input())
	x = int(input())
	orig = findOriginal(s, x)
	enc = findEncoded(orig, x)
	if enc == s:
		print(''.join(orig))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = list(input())
	x = int(input())
	n = len(s)
	res = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				res[i + x] = '0'
			if i - x >= 0:
				res[i - x] = '0'
	flag = True
	for i in range(n):
		if s[i] == '1':
			a = True
			b = True
			if i + x >= n:
				b = False
			if i - x < 0:
				a = False
			if i + x < n and res[i + x] == '0':
				b = False
			if i - x >= 0 and res[i - x] == '0':
				a = False
			if a == False and b == False:
				flag = False
				break
	if flag == 0:
		print(-1)
	else:
		print(''.join(res))


import math
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	s = input()
	x = I()
	w = ['1'] * len(s)
	flag = 1
	for i in range(len(s)):
		if s[i] == '0':
			if i + 1 > x:
				w[i + 1 - x - 1] = '0'
			if i + 1 + x <= len(s):
				w[i + 1 + x - 1] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			g = 0
			if i + 1 > x:
				if w[i + 1 - x - 1] == '1':
					g = 1
			if i + 1 + x <= len(s):
				if w[i + 1 + x - 1] == '1':
					g = 1
			if g == 0:
				flag = 0
				break
	if flag == 0:
		print(-1)
	else:
		for i in w:
			print(i, end='')
		print()


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	w = ['a'] * len(s)
	for j in range(len(s)):
		if s[j] == '0':
			if j >= x:
				w[j - x] = '0'
			if j + x < len(s):
				w[j + x] = '0'
	flag = 0
	for j in range(len(s)):
		flag = 0
		if s[j] == '1':
			if j >= x:
				if w[j - x] == '0':
					flag += 1
				else:
					w[j - x] = '1'
			else:
				flag += 1
			if j + x < len(s):
				if w[j + x] == '0':
					flag += 1
				else:
					w[j + x] = '1'
			else:
				flag += 1
		if flag == 2:
			break
	if flag == 2:
		print(-1)
	else:
		for j in range(len(w)):
			if w[j] == 'a':
				w[j] = '1'
		print(''.join(w))


def solv():
	main = input()
	x = int(input())
	ans = ['-'] * len(main)
	for i in range(len(main)):
		if main[i] == '0':
			if x <= i:
				ans[i - x] = '0'
			if x + i < len(ans):
				ans[i + x] = '0'
	for i in range(len(main)):
		if ans[i] != '0':
			ans[i] = '1'
	for i in range(len(main)):
		if main[i] == '1':
			if not (x <= i and ans[i - x] == '1' or (x + i < len(ans) and ans[i + x] == '1')):
				print('-1')
				return
	print(*ans, sep='')
for _ in range(int(input())):
	solv()


def get():
	n = len(s)
	w = [1] * n
	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
	for i in range(n):
		if s[i]:
			if i - x >= 0 and w[i - x] == 1:
				continue
			elif i + x < n and w[i + x] == 1:
				continue
			else:
				return [-1]
	return w
for _ in range(int(input())):
	s = list(map(int, input()))
	x = int(input())
	for i in get():
		print(i, end='')
	print()


t = int(input())
while t:
	s = input()
	x = int(input())
	ans = ['1' for i in range(len(s))]
	for i in range(len(s)):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = '0'
			if i + x < len(s):
				ans[i + x] = '0'
	ans2 = ['1' for i in range(len(ans))]
	for i in range(len(ans)):
		if (i < x or ans[i - x] == '0') and (i + x >= len(ans) or ans[i + x] == '0'):
			ans2[i] = '0'
	s2 = ''.join(ans2)
	if s == s2:
		print(''.join(ans))
	else:
		print('-1')
	t = t - 1


for _ in range(int(input())):
	(s, x) = (input(), int(input()))
	n = len(s)
	w = ['1' for i in range(n)]
	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'
	valid = True
	for i in range(n):
		if s[i] == '1':
			can = False
			if i - x >= 0 and w[i - x] == '1':
				can = True
			if i + x < n and w[i + x] == '1':
				can = True
			valid &= can
	print(''.join(w)) if valid else print('-1')


for _ in range(int(input())):
	S = input()
	x = int(input())
	s = ''
	n = len(S)
	for i in range(n):
		if x <= i and S[i - x] == '0' or (i < n - x and S[i + x] == '0'):
			s += '0'
		else:
			s += '1'
	for i in range(n):
		if S[i] == '1':
			if x <= i and s[i - x] == '1' or (i < n - x and s[i + x] == '1'):
				continue
			else:
				s = -1
				break
	print(s)


for _ in range(int(input())):
	string = list(input())
	x = int(input())
	len_str = len(string)
	w = ['1' for _ in range(len_str)]
	for (ind, s) in enumerate(string):
		if s == '0':
			if ind - x >= 0:
				w[ind - x] = '0'
			if ind + x < len_str:
				w[ind + x] = '0'
	test = ['0' for _ in range(len_str)]
	for ind in range(0, len_str):
		if ind + x < len_str:
			if w[ind + x] == '1':
				test[ind] = '1'
				continue
		if ind - x >= 0:
			if w[ind - x] == '1':
				test[ind] = '1'
				continue
	if test == string:
		print(''.join(w))
	else:
		print(-1)


import sys
input = sys.stdin.readline
T = int(input())
while T:
	s = list(input())[:-1]
	x = int(input())
	n = len(s)
	w = ['1' for i in range(n)]
	r = ''
	for i in range(n):
		if s[i] == '0':
			if i - x > -1:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i + x >= n and i - x < 0:
				r = -1
				break
			elif i + x < n and i - x > -1:
				if w[i + x] == '0' and w[i - x] == '0':
					r = -1
					break
			elif i + x < n:
				if w[i + x] == '0':
					r = -1
					break
			elif i - x > -1:
				if w[i - x] == '0':
					r = -1
					break
	if r == -1:
		print(r)
	else:
		r = ''.join((i for i in w))
		print(r)
	T = T - 1


t = int(input())
while t > 0:
	t -= 1
	s = str(input())
	x = int(input())
	S = set()
	for i in range(0, len(s)):
		if s[i] == '0':
			S.add(i + x)
			S.add(i - x)
	indicator = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			c = 0
			if i - x >= 0 and i - x not in S:
				c += 1
			if i + x < len(s) and i + x not in S:
				c += 1
			if c == 0:
				indicator = 1
	if indicator == 0:
		for i in range(0, len(s)):
			if i in S:
				print('0', end='')
			else:
				print('1', end='')
		print('')
	else:
		print(-1)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def check(a, b, x):
	c = ['*' for i in range(len(a))]
	for i in range(len(a)):
		if i - x >= 0 and a[i - x] == '1':
			c[i] = '1'
		elif i + x < len(a) and a[i + x] == '1':
			c[i] = '1'
		else:
			c[i] = '0'
	c = ''.join(c)
	return c == b

def solve():
	s = list(input())
	if s[-1] == '\n':
		s.pop()
	a = ['1' for _ in range(len(s))]
	x = int(input())
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				a[i - x] = '0'
			if i + x < len(s):
				a[i + x] = '0'
	a = ''.join(a)
	s = ''.join(s)
	if check(a, s, x):
		print(a)
	else:
		print(-1)
for _ in range(int(input())):
	solve()


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		s = si()
		x = ii()
		n = len(s)
		s1 = ['1'] * n
		flag = [0] * n
		for i in range(n):
			x1 = i - x
			x2 = i + x
			ok = False
			if s[i] == '0':
				f = 0
				if x1 >= 0:
					f = 1
					if flag[x1] == 0:
						s1[x1] = '0'
						ok = True
					else:
						break
				if x2 < n:
					s1[x2] = '0'
					ok = True
					f = 1
				if f == 0:
					ok = True
			elif x1 >= 0 and s1[x1] == '1':
				ok = True
			elif x2 < n:
				ok = True
				flag[x2] = 1
			if ok == False:
				break
		if ok == False:
			print('-1')
		else:
			print(''.join(s1))
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	x = int(input())
	w = [0] * n
	for i in range(n):
		if 0 <= i + x < n and 0 <= i - x < n:
			if s[i + x] == '1' and s[i - x] == '1':
				w[i] = 1
		elif 0 <= i + x < n:
			if s[i + x] == '1':
				w[i] = 1
		elif 0 <= i - x < n:
			if s[i - x] == '1':
				w[i] = 1
	for i in range(n):
		if 0 <= i - x < n and w[i - x] == 1:
			if s[i] == '1':
				continue
			else:
				print(-1)
				break
		if 0 <= i + x < n and w[i + x] == 1:
			if s[i] == '1':
				continue
			else:
				print(-1)
				break
		if s[i] == '1':
			print(-1)
			break
	else:
		print(*w, sep='')


import sys

def main():
	tn = int(input())
	for ti in range(tn):
		S = input().strip()
		n = len(S)
		W = [''] * n
		x = int(input())
		is_ok = True
		for (i, s) in enumerate(S):
			if s == '1':
				continue
			if i - x >= 0:
				W[i - x] = '0'
			if i + x < n:
				W[i + x] = '0'
		for (i, s) in enumerate(S):
			if s == '0':
				continue
			c = 0
			if i - x >= 0 and W[i - x] == '':
				c += 1
			if i + x < n and W[i + x] == '':
				c += 1
			if c == 0:
				is_ok = False
		print(''.join(map(lambda x: x if x == '0' else '1', W)) if is_ok else '-1')
main()


t = int(input())
while True:
	if t == 0:
		break
	t -= 1
	a = input()
	n = len(a)
	x = int(input())
	w = ['1' for i in range(n + 1)]
	s = ['1']
	for i in a:
		s.append(i)
	for i in range(1, n + 1):
		if i > x and s[i] == '1':
			if w[i - x] != '0':
				w[i - x] = '1'
		if i + x <= n and s[i] == '1':
			if w[i + x] != 0:
				w[i + x] = '1'
		if s[i] == '0':
			if i > x:
				w[i - x] = '0'
			if i + x <= n:
				w[i + x] = '0'
	poss = True
	for i in range(1, n + 1):
		if i > x and w[i - x] == '1' or (i + x <= n and w[i + x] == '1'):
			if s[i] != '1':
				poss = False
				break
		elif s[i] != '0':
			poss = False
			break
	if poss:
		print(''.join(w[1:]))
	else:
		print(-1)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		s = rs()
		x = ri()
		ans = [1] * len(s)
		for i in range(len(s)):
			if s[i] == '0':
				if i - x >= 0:
					ans[i - x] = 0
				if i + x < len(s):
					ans[i + x] = 0
		c = True
		k = ''
		for i in range(len(s)):
			if i - x >= 0 and ans[i - x] == 1 or (i + x < len(s) and ans[i + x] == 1):
				k += '1'
			else:
				k += '0'
		if k == s:
			print(''.join((str(i) for i in ans)))
		else:
			print(-1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import math
t = int(input())
while t > 0:
	t -= 1
	s = input()
	x = int(input())
	confuse = []
	ans = [-1] * len(s)
	flag = False
	for i in range(len(s)):
		if s[i] == '1':
			if i - x < 0:
				if i + x < len(s):
					if ans[i + x] == 0:
						print(-1)
						flag = True
						break
				else:
					print(-1)
					flag = True
					break
				ans[i + x] = 1
			elif ans[i - x] == 1:
				continue
			elif ans[i - x] == 0:
				if i + x >= len(s) or ans[i + x] == 0:
					print(-1)
					flag = True
					break
				else:
					ans[i + x] = 1
			elif i + x < len(s):
				if ans[i + x] == 1:
					continue
				elif ans[i + x] == 0:
					ans[i - x] = 1
					continue
				else:
					confuse.append((i - x, i + x))
			else:
				ans[i - x] = 1
		elif i - x >= 0:
			if ans[i - x] == 1:
				print(-1)
				flag = True
				break
			else:
				ans[i - x] = 0
				if i + x < len(s):
					if ans[i + x] == 1:
						print(-1)
						flag = True
						break
					else:
						ans[i + x] = 0
		elif i + x < len(s):
			if ans[i + x] == 1:
				print(-1)
				flag = True
				continue
			else:
				ans[i + x] = 0
		else:
			pass
	if not flag:
		for pair in confuse:
			if ans[pair[0]] == 0 and ans[pair[1]] == 0:
				print(-1)
				flag = True
				break
		if not flag:
			for i in range(len(s)):
				if ans[i] == -1:
					ans[i] = 1
				ans[i] = str(ans[i])
			print(''.join(ans))


for t in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	a = ['1' for i in range(n)]
	for i in range(n):
		if i + x < n and s[i] == '0':
			a[i + x] = '0'
		if i - x >= 0 and s[i] == '0':
			a[i - x] = '0'
	f = True
	for i in range(n):
		flag = False
		flag = flag or (i + x < n and a[i + x] == '1')
		flag = flag or (i - x >= 0 and a[i - x] == '1')
		if s[i] == '1' and flag == False or (s[i] == '0' and flag):
			f = False
			print(-1)
			break
	if f:
		for i in a:
			print(i, end='')
		print()


for i in range(int(input())):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			flag = False
			if i - x >= 0:
				if w[i - x] == '1':
					flag = True
			if i + x < len(s):
				if w[i + x] == '1':
					flag = True
			if not flag:
				print(-1)
				break
	else:
		ans = ''.join(w)
		print(ans)


t = int(input(''))
for k in range(t):
	s = input('')
	x = int(input(''))
	w = []
	f = 0
	ws = ''
	for l in range(len(s)):
		w.append('1')
	for i in range(len(s)):
		if i >= x and s[i] == '0':
			w[i - x] = '0'
		if i + x < len(s) and s[i] == '0':
			w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if i >= x and w[i - x] == '1' or (i + x < len(s) and w[i + x] == '1'):
				f = 0
			else:
				f = 1
				break
	for i in w:
		ws += i
	if f == 1:
		print(-1)
	else:
		print(ws)


for _ in range(int(input())):
	s = input()
	x = int(input())
	flag = True
	ans = ['2'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				if ans[i + x] == '1':
					flag = False
					break
				ans[i + x] = '0'
			if i - x >= 0:
				if ans[i - x] == '1':
					flag = False
					break
				ans[i - x] = '0'
		elif s[i] == '1':
			if i + x >= len(s) and i - x < 0:
				flag = False
				break
			if i + x < len(s) and i - x < 0:
				if ans[i + x] == '0':
					flag = False
					break
				ans[i + x] = '1'
			elif i + x >= len(s) and i - x >= 0:
				if ans[i - x] == '0':
					flag = False
					break
				ans[i - x] = '1'
			elif i + x < len(s) and i - x >= 0:
				if ans[i - x] == '0' and ans[i + x] == '0':
					flag = False
					break
				elif ans[i - x] == '0':
					ans[i + x] = '1'
				elif ans[i + x] == '0':
					ans[i - x] = '1'
	temp = ''
	for i in range(len(s)):
		if ans[i] == '2':
			ans[i] = '1'
			temp += ans[i]
		else:
			temp += ans[i]
	if flag:
		print(temp)
	else:
		print('-1')


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		st = get_input()
		n = len(st)
		x = get_int_input()
		w = ['1'] * n
		for i in range(n):
			if st[i] == '0':
				if i >= x:
					w[i - x] = '0'
				if i + x < n:
					w[i + x] = '0'
		for i in range(n):
			val1 = None
			val2 = None
			if i >= x:
				val1 = w[i - x]
			if i + x < n:
				val2 = w[i + x]
			if st[i] == '0':
				if val1 and val1 != '0':
					w = ['-1']
					break
				if val2 and val2 != '0':
					w = ['-1']
					break
			if st[i] == '1':
				if val1 and val1 == '1':
					continue
				if val2 and val2 == '1':
					continue
				w = ['-1']
				break
		res = ''.join(w)
		cout << res << endl

def main():
	solve()
main()


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	ss = input()
	n = len(ss)
	x = int(input())
	res = ['0'] * n
	for i in range(n):
		if (i - x < 0 or ss[i - x] == '1') and (i + x >= n or ss[i + x] == '1'):
			res[i] = '1'
	for i in range(n):
		if ss[i] == '1' and (i - x < 0 or res[i - x] == '0') and (i + x >= n or res[i + x] == '0'):
			print(-1)
			return
	print(''.join(res))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
import bisect
t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	l = ['2'] * n
	ch = 1
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				l[i - x] = s[i]
			if i + x < n:
				l[i + x] = s[i]
	for i in range(n):
		if l[i] == '2':
			l[i] = '1'
	for i in range(n):
		cnt1 = 0
		if i - x >= 0:
			if l[i - x] == '1':
				cnt1 += 1
		if i + x < n:
			if l[i + x] == '1':
				cnt1 += 1
		if s[i] == '1':
			if cnt1 == 0:
				ch = 0
				break
	if ch == 0:
		print(-1)
	else:
		print(*l, sep='')


t = int(input())
for w in range(t):
	q = str(input(''))
	x = int(input())
	n = len(q)
	ans = ['1' for i in q]
	for i in range(0, n):
		if q[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	ll = False
	rr = False
	flag = True
	for i in range(0, n):
		if q[i] == '1':
			ll = False
			rr = False
			if i - x >= 0:
				if ans[i - x] == '1':
					ll = True
			if i + x < n:
				if ans[i + x] == '1':
					rr = True
			if (ll or rr) == False:
				flag = False
				break
	if flag:
		print(''.join(ans))
	else:
		print('-1')


t = int(input())
for case in range(t):
	s = input()
	s = '2' + s
	length = len(s)
	x = int(input())
	w = [1] * length
	valid = True
	for i in range(1, length):
		if s[i] == '0':
			if i > x:
				w[i - x] = 0
			if i < length - x:
				w[i + x] = 0
	for i in range(1, length):
		if s[i] == '1':
			if i > x and i < length - x:
				if w[i - x] == 0 and w[i + x] == 0:
					valid = False
					break
			elif i <= x and i >= length - x:
				valid = False
				break
			elif i > x and i >= length - x:
				if w[i - x] == 0:
					valid = False
					break
			elif i <= x and i < length - x:
				if w[i + x] == 0:
					valid = False
					break
	if valid:
		print(''.join(map(str, w[1:])))
	else:
		print(-1)


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split()))

def read_floats():
	return list(map(float, input().strip().split()))

def read_str():
	return input().strip()

def solve_t():
	s = read_str()
	x = read_int()
	n = len(s)
	w = list('1' * n)
	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'
	for i in range(n):
		if s[i] == '1':
			invalid = True
			if i - x >= 0 and w[i - x] == '1':
				invalid = False
			if i + x < n and w[i + x] == '1':
				invalid = False
			if invalid:
				print(-1)
				return
	print(''.join(w))

def solve():
	t = read_int()
	for _ in range(t):
		solve_t()
solve()


for _ in range(int(input())):
	s = input().strip()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				w[i + x] = '0'
			if i - x >= 0:
				w[i - x] = '0'
	ok = True
	for i in range(n):
		if s[i] == '1':
			ok = False
			if i + x < n and w[i + x] != '0':
				ok = True
			if i - x >= 0 and w[i - x] != '0':
				ok = True
			if not ok:
				break
	if ok:
		print(''.join(w))
	else:
		print(-1)


def findBin(s, x):
	n = len(s)
	w = [-1] * n
	for i in range(n):
		if i >= x:
			a = int(s[i - x])
		else:
			a = 1
		if i + x < n:
			b = int(s[i + x])
		else:
			b = 1
		w[i] = str(a & b)
	for i in range(n):
		(a, b) = (0, 0)
		if i >= x and w[i - x] == '1':
			a = 1
			if s[i] != '1':
				return -1
		if i + x < n and w[i + x] == '1':
			b = 1
			if s[i] != '1':
				return -1
		if not (a or b) and s[i] != '0':
			return -1
	return ''.join(w)
t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	print(findBin(s, x))


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def count1(s):
	c = 0
	for i in s:
		if i == '1':
			c += 1
	return c

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True
for xyz in range(0, int(input())):
	s = input()
	k = int(input())
	n = len(s)
	ans = ['1'] * n
	pos = []
	f = True
	for i in range(0, n):
		if s[i] == '0':
			pos.append(i)
		if i + k >= n and i - k < 0:
			ans[i] = '0'
	for i in pos:
		if i - k >= 0 or i + k < n:
			if i - k < 0:
				ans[i + k] = '0'
			elif i + k >= n:
				ans[i - k] = '0'
			else:
				ans[i - k] = ans[i + k] = '0'
	for i in range(0, n):
		if i - k >= 0 or i + k < n:
			if i - k < 0:
				if ans[i + k] != s[i]:
					f = False
					break
			elif i + k >= n:
				if ans[i - k] != s[i]:
					f = False
					break
			elif int(ans[i - k]) | int(ans[i + k]) != int(s[i]):
				f = False
				break
		elif ans[i] != s[i]:
			f = False
			break
	if f:
		print(''.join(ans))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i < len(s) - x:
				ans[i + x] = '0'
			if i >= x:
				ans[i - x] = '0'
	correct = True
	for j in range(len(s)):
		result = '0'
		if j < len(s) - x and ans[j + x] == '1':
			result = '1'
		if j >= x and ans[j - x] == '1':
			result = '1'
		if result != s[j]:
			correct = False
	if correct:
		print(*ans, sep='')
	else:
		print('-1')


try:
	for i in range(int(input())):
		s = str(input())
		x = int(input())
		n = len(s)
		z = x
		st = ''
		string = ['1'] * n
		for i in range(len(s)):
			if s[i] == '0':
				if i >= z:
					string[i - z] = '0'
				if i + z < len(s):
					string[i + z] = '0'
		for i in range(len(s)):
			if s[i] == '1':
				count1 = 0
				count2 = 0
				if i >= z and string[i - z] == '1':
					count1 += 1
				else:
					count2 += 1
				if i + z < len(s) and string[i + z] == '1':
					count1 += 1
				else:
					count2 += 1
				if count1 == 0:
					string = ['-1']
					break
		for i in string:
			st += i
		print(st)
except Exception as e:
	pass


class Conflict(Exception):
	pass

def controller(s, x):
	n = len(s)
	s = [int(i) for i in s]
	w = [-1] * n
	constraints = []

	def set(idx, val):
		if w[idx] != val:
			if w[idx] != -1:
				raise Conflict()
			w[idx] = val
	try:
		for i in range(n):
			(a, b) = (i - x, i + x)
			(has_a, has_b) = (a >= 0, b < n)
			if has_a and has_b:
				if s[i] == 0:
					set(a, 0)
					set(b, 0)
				else:
					constraints.append(i)
			elif has_a:
				set(a, s[i])
			elif has_b:
				set(b, s[i])
			elif s[i] != 0:
				raise Conflict()
		for i in constraints:
			if w[i - x] < 0:
				w[i - x] = 1
			elif w[i + x] < 0:
				w[i + x] = 1
			elif w[i - x] + w[i + x] == 0:
				raise Conflict()
	except Conflict:
		return -1
	return ''.join(('1' if i < 0 else str(i) for i in w))

def c_in():
	import sys, os
	try:
		file = open(os.path.join(sys.argv[0], '../in-c-2.txt'))
	except:
		file = sys.stdin
	n_test_case = int(file.readline())
	for i in range(n_test_case):
		w = file.readline().rstrip()
		x = int(file.readline())
		print(controller(w, x))
c_in()


import os, sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd

def lcm(x, y):
	return x * y // gcd(x, y)

def main():
	for _ in range(int(input())):
		s = input().strip()
		x = int(input())
		n = len(s)
		w = ['1' for i in range(n)]
		for i in range(n):
			if s[i] == '0':
				if i >= x:
					w[i - x] = s[i]
				if i < n - x:
					w[i + x] = s[i]
		z = ['0' for j in range(n)]
		for i in range(n):
			if i - x >= 0:
				if w[i - x] == '1':
					z[i] = '1'
			if i + x <= n - 1:
				if w[i + x] == '1':
					z[i] = '1'
		if s == ''.join(z):
			print(''.join(w))
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


ttt = int(input())
for _ in range(ttt):
	S = [ord(c) - ord('0') for c in input()]
	x = int(input())
	n = len(S)
	anss = [1] * n
	for i in range(n):
		if S[i] == 0:
			if 0 <= i - x:
				anss[i - x] = 0
			if i + x < n:
				anss[i + x] = 0
	T = [0] * n
	for i in range(n):
		if 0 <= i - x and anss[i - x]:
			T[i] = 1
		if i + x < n and anss[i + x]:
			T[i] = 1
	if S == T:
		print(''.join((str(x) for x in anss)))
	else:
		print(-1)


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve(c1, c2, maxi1, maxi2):
	for i in range(1, maxi1 + 1):
		if i not in c1:
			return False
	for i in range(1, maxi2 + 1):
		if i not in c2:
			return False
	return True

def main():
	for _ in range(iin()):
		s = sin()
		x = iin()
		n = len(s)
		l = ['1'] * n
		for i in range(n):
			if s[i] == '0':
				if i - x >= 0:
					l[i - x] = '0'
				if i + x < n:
					l[i + x] = '0'
		flag = 1
		for i in range(n):
			c = 0
			if s[i] == '1':
				if i - x >= 0:
					if l[i - x] == '1':
						c = 1
				if i + x < n:
					if l[i + x] == '1':
						c = 1
				if c == 0:
					flag = 0
					break
		if not flag:
			print(-1)
		else:
			print(''.join(l))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for o in range(t):
	m = list(map(int, input()))
	x = int(input())
	n = len(m)
	a = [0] * n
	ans = [0] * n
	for i in range(n):
		if m[i] == 0:
			if i - x >= 0:
				a[i - x] = 1
			if i + x < n:
				a[i + x] = 1
	for i in range(n):
		f = 0
		if m[i] == 1:
			if i - x >= 0 and a[i - x] == 0:
				ans[i - x] = 1
				f = 1
			if i + x < n and a[i + x] == 0:
				ans[i + x] = 1
				f = 1
		else:
			f = 1
		if f == 0:
			break
	if f == 0:
		print(-1)
	else:
		print(*ans, sep='')


from sys import stdin, stdout

def find(S, X):
	N = len(S)
	K = [1] * N
	for i in range(N):
		if S[i] == 0:
			if i - X >= 0:
				K[i - X] = 0
			if i + X < N:
				K[i + X] = 0
	for i in range(N):
		if i >= X and K[i - X] == 1 or (i + X < N and K[i + X] == 1):
			if S[i] == 0:
				return -1
		elif S[i] == 1:
			return -1
	return ''.join(map(str, K))

def main():
	for _ in range(int(stdin.readline())):
		S = list(map(int, list(stdin.readline().strip())))
		N = int(stdin.readline())
		print(find(S, N))
main()


import sys, math
import io, os
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
INF = float('inf')
mod = int(1000000000.0) + 7

def cal(p, f, cnts, cntw, s, w):
	cnts1 = min(cnts, p // s)
	ans = cnts1
	p = p - cnts1 * s
	cnts -= cnts1
	while cnts and cntw and (p + s >= w):
		p += s - w
		cnts += 1
		cntw -= 1
	cntw1 = min(cntw, p // w)
	ans += cntw1
	p = p - cntw1 * s
	cntw -= cntw1
	cnts1 = min(cnts, f // s)
	ans += cnts1
	f = f - cnts1 * s
	cnts -= cnts1
	cntw1 = min(cntw, f // w)
	ans += cntw1
	f = f - cntw1 * s
	cntw -= cntw1
	return ans
for t in range(int(data())):
	s = data()
	x = int(data())
	s1 = [0] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				s1[i + x] = s[i]
			if i - x >= 0:
				s1[i - x] = s[i]
		else:
			if i + x < len(s) and s1[i + x] == 0:
				s1[i + x] = s[i]
			if i - x >= 0 and s1[i - x] == 0:
				s1[i - x] = s[i]
	for i in range(len(s)):
		if s1[i] == 0:
			s1[i] = '0'
	k = 1
	s2 = ['0' for i in range(len(s))]
	for i in range(len(s)):
		if i + x < len(s) and s1[i + x] == '1':
			s2[i] = '1'
		if i - x >= 0 and s1[i - x] == '1':
			s2[i] = '1'
	if ''.join(s2) != s:
		out(-1)
	else:
		out(''.join(s1))


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	f = 0
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
				f = 0
			else:
				f = 1
				break
	a = ''
	for i in ans:
		a += i
	if f == 1:
		print(-1)
	else:
		print(a)


tc = int(input())
for _ in range(tc):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x > -1:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	s2 = ''
	for i in range(len(s)):
		if i - x > -1 and w[i - x] == '1':
			if w[i - x] == '1':
				s2 += '1'
		elif i + x < len(s) and w[i + x] == '1':
			if w[i + x] == '1':
				s2 += '1'
		else:
			s2 += '0'
	ans = ''.join(w)
	if s2 == s:
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	a = ['?'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				a[i + x] = '0'
			if i - x >= 0:
				a[i - x] = '0'
	temp = 0
	for i in range(len(s)):
		if s[i] == '1':
			if i + x < len(s) and a[i + x] == '?':
				continue
			elif i - x >= 0 and a[i - x] == '?':
				continue
			else:
				temp = 1
	if temp == 1:
		print(-1)
	else:
		ans = ''
		for i in range(len(s)):
			if a[i] == '?':
				ans += '1'
			else:
				ans += '0'
		print(ans)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def check(s, n, v):
	for i in range(n):
		if s[i:i + n].count(v) == 0:
			return False
	return True

def solve():
	s = minp()
	x = mint()
	n = len(s)
	a = [None] * n
	for i in range(n):
		if i - x >= 0:
			if i + x < n:
				if s[i] == '0':
					if a[i + x] is not None and a[i + x] != '0':
						print(-1)
						return
					if a[i - x] is not None and a[i - x] != '0':
						print(-1)
						return
					a[i - x] = '0'
					a[i + x] = '0'
			else:
				if a[i - x] is not None and a[i - x] != s[i]:
					print(-1)
					return
				a[i - x] = s[i]
		elif i + x < n:
			if a[i + x] is not None and a[i + x] != s[i]:
				print(-1)
				return
			a[i + x] = s[i]
	for i in range(n):
		if a[i] is None:
			a[i] = '1'
	for i in range(n):
		c = '0'
		if i - x >= 0 and a[i - x] == '1':
			c = '1'
		elif i + x < n and a[i + x] == '1':
			c = '1'
		if s[i] != c:
			print(-1)
			return
	print(''.join(a))
for i in range(mint()):
	solve()


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	s = rs()
	x = ri()
	n = len(s)
	fuck = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				fuck[i - x] = '0'
			if i + x < n:
				fuck[i + x] = '0'
	fuckoff = ''
	for i in range(n):
		if i >= x and fuck[i - x] == '1':
			fuckoff += '1'
		elif i + x < n and fuck[i + x] == '1':
			fuckoff += '1'
		else:
			fuckoff += '0'
	fuck = ''.join(fuck)
	ws(fuck) if fuckoff == s else wi(-1)


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	a = [int(i) for i in s]
	w = [None] * n
	for i in range(n):
		if a[i] == 0:
			if i - x >= 0:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	flag = 0
	for i in range(n):
		if a[i] == 1:
			if i - x >= 0 and w[i - x] == 0:
				if i + x < n and w[i + x] == 0 or i + x >= n:
					flag = 1
					break
			if i + x < n and w[i + x] == 0:
				if i - x >= 0 and w[i - x] == 0 or i - x < 0:
					flag = 1
					break
			if i + x >= n and i - x < 0:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		t = w.copy()
		for i in range(n):
			if t[i] == None:
				w[i] = str(1)
			else:
				w[i] = str(t[i])
		st = ''.join(w)
		print(st)


import os
from sys import stdin, stdout

def solve(tc):
	s = stdin.readline().strip()
	x = int(stdin.readline().strip())
	n = len(s)
	ans = [1 for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] or (i + x < n and ans[i + x]):
				pass
			else:
				print(-1)
				return
	print(*ans, sep='')
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	s = stdin.readline().strip('\n')
	x = int(stdin.readline())
	n = len(s)
	a = [-1] * n
	res = True
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and a[i - x] != 0:
				a[i - x] = 1
				continue
			if i + x < n:
				if a[i + x] == 0:
					res = False
					break
				else:
					a[i + x] = 1
					continue
			res = False
			break
		else:
			if i - x >= 0:
				if a[i - x] == 1:
					res = False
					break
				else:
					a[i - x] = 0
			if i + x < n:
				if a[i + x] == 1:
					res = False
					break
				else:
					a[i + x] = 0
	ans = ''
	for i in range(n):
		if a[i] != -1:
			ans = ans + str(a[i])
		else:
			ans = ans + '1'
	if res:
		print(ans)
	else:
		print(-1)


t = int(input())
Ans = []
for k in range(t):
	s = input()
	s = [int(j) for j in s]
	x = int(input())
	w = [1] * len(s)
	for i in range(len(s)):
		if s[i] == 0:
			if i + 1 > x:
				w[i - x] = 0
			if i + x + 1 <= len(s):
				w[i + x] = 0
	for i in range(len(s)):
		if s[i] == 1:
			if i + 1 > x and w[i - x] == 0 and (i + x + 1 > len(s)) or (i + x + 1 <= len(s) and w[i + x] == 0 and (i + 1 <= x)) or (i + 1 > x and w[i - x] == 0 and (i + x + 1 <= len(s)) and (w[i + x] == 0)) or (i + x + 1 > len(s) and i + 1 <= x):
				Ans.append(-1)
				break
	if len(Ans) == k:
		Ans.append(''.join((str(j) for j in w)))
for i in Ans:
	print(i)


t = int(input())
from collections import defaultdict

class FailUpdate(Exception):
	pass

def must_have_value(w, idx, val):
	if w[idx] != '' and w[idx] != val:
		raise FailUpdate()
	w[idx] = val

def solve():
	s = input()
	n = len(s)
	x = int(input())
	w = [''] * n
	deps = defaultdict(list)
	for i in range(0, n):
		left = i - x
		right = i + x
		if left >= 0:
			deps[i].append(left)
		if right <= n - 1:
			deps[i].append(right)
	try:
		for i in range(n):
			if len(deps[i]) == 0 and s[i] == '1':
				return -1
		for i in range(n):
			if len(deps[i]) == 1:
				must_have_value(w, deps[i][0], s[i])
		for i in range(n):
			if len(deps[i]) == 2 and s[i] == '0':
				(dep1, dep2) = deps[i]
				must_have_value(w, dep1, '0')
				must_have_value(w, dep2, '0')
	except FailUpdate:
		return '-1'
	for i in range(n):
		if len(deps[i]) == 2 and s[i] == '1':
			(dep1, dep2) = deps[i]
			if w[dep1] == '0' and w[dep2] == '0':
				return '-1'
	for i in range(n):
		if w[i] == '':
			w[i] = '1'
	return ''.join(w)
for __ in range(t):
	print(solve())


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	s = input()
	x = Int()
	n = len(s)
	w = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				w[i + x] = 0
			if i - x >= 0:
				w[i - x] = 0
	ok = True
	for i in range(n):
		if s[i] == '0':
			if i + x < n and w[i + x] == 1:
				ok = False
			if i - x >= 0 and w[i - x] == 1:
				ok = False
		elif i + x >= n or w[i + x] == 0:
			if i - x < 0 or w[i - x] == 0:
				ok = False
	if ok:
		print(*w, sep='')
	else:
		print(-1)


t = int(input())

def solve():
	s = input()
	x = int(input())
	w = [None] * len(s)
	for (i, dig) in enumerate(s):
		if dig == '0':
			if i + x < len(s):
				w[i + x] = 0
			if i - x >= 0:
				w[i - x] = 0
	for i in range(len(s)):
		if w[i] == None:
			w[i] = 1
	recreated_s = [None] * len(s)
	for i in range(len(s)):
		if i + x < len(s) and w[i + x] == 1:
			recreated_s[i] = '1'
		elif i - x >= 0 and w[i - x] == 1:
			recreated_s[i] = '1'
		else:
			recreated_s[i] = '0'
	if ''.join(recreated_s) == s:
		print(''.join(map(str, w)))
	else:
		print(-1)
while t:
	solve()
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		x = int(input())
		n = len(s)
		ans = [1] * n
		for i in range(1, n + 1):
			if s[i - 1] == '0':
				if i > x:
					ans[i - x - 1] = 0
				if i + x <= n:
					ans[i + x - 1] = 0
		for i in range(1, n + 1):
			if s[i - 1] == '1':
				(f1, f2) = (False, False)
				if i > x and ans[i - x - 1] == 1:
					f1 = True
				if i + x <= n and ans[i + x - 1] == 1:
					f2 = True
				if f1 or f2:
					pass
				else:
					ans = None
					break
		if not ans:
			print(-1)
		else:
			print(*ans, sep='')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	s = list(input())
	n = len(s)
	x = int(input())
	ans = ['1'] * n
	b = ['0'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		if i - x >= 0 and ans[i - x] == '1':
			b[i] = '1'
		if i + x < n and ans[i + x] == '1':
			b[i] = '1'
	if s == b:
		print(''.join(ans))
	else:
		print(-1)


for _ in range(int(input())):
	s = str(input())
	x = int(input())
	n = len(s)
	temp = True
	ans = [1 for l in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i < x and i + x >= n:
				temp = False
				break
			elif i >= x and i + x >= n and (ans[i - x] == 0):
				temp = False
				break
			elif i < x and i + x < n and (ans[i + x] == 0):
				temp = False
				break
			elif i >= x and i + x < n and (ans[i + x] == 0) and (ans[i - x] == 0):
				temp = False
				break
			else:
				pass
	if temp:
		ans = list(map(str, ans))
		res = ''.join(ans)
		print(res)
	else:
		print('-1')


for _ in range(int(input())):
	s = list(map(int, list(input())))
	x = int(input())
	n = len(s)
	a = [1 for i in range(n)]
	for i in range(n):
		if i - x >= 0 and s[i] == 0:
			a[i - x] = 0
		if i + x < n and s[i] == 0:
			a[i + x] = 0
	temp = [0 for i in range(n)]
	flag = 1
	for i in range(n):
		if i - x >= 0:
			temp[i] |= a[i - x]
		if i + x < n:
			temp[i] |= a[i + x]
		if temp[i] != s[i]:
			flag = 0
			break
	print(''.join(list(map(str, a))) if flag == 1 else -1)


def check(ans, s, x, n):
	temp = ['0' for i in range(n)]
	for i in range(1, n + 1):
		if i - x > 0 and ans[i - x] == '1':
			temp[i - 1] = '1'
		if i + x <= n and ans[i + x] == '1':
			temp[i - 1] = '1'
	return temp == s
for _ in range(int(input())):
	s = list(input())
	x = int(input())
	n = len(s)
	ans = ['1' for i in range(n + 1)]
	for i in range(1, n + 1):
		if s[i - 1] == '0':
			if i - x > 0:
				ans[i - x] = '0'
			if i + x <= n:
				ans[i + x] = '0'
	if check(ans, s, x, n):
		print(''.join(ans[1:]))
	else:
		print(-1)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	ans = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i + x <= n - 1:
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	w = ''.join(ans)
	flag = True
	for i in range(len(w)):
		t1 = False
		t2 = False
		if s[i] == '1':
			if i + x <= n - 1 and w[i + x] == '1':
				t1 = True
			if i - x >= 0 and w[i - x] == '1':
				t2 = True
			if not t1 and (not t2):
				flag = False
				break
		else:
			if i + x <= n - 1 and w[i + x] == '1':
				flag = False
				break
			if i - x >= 0 and w[i - x] == '1':
				flag = False
				break
	if flag:
		print(w)
	else:
		print(-1)


t = int(input())
for i in range(t):
	s = input()
	b = []
	for j in s:
		b.append(int(j))
	n = len(b)
	y = int(input())
	c = [1] * n
	j = 0
	f = 0
	while j < n:
		if b[j] == 0:
			if j - y >= 0:
				c[j - y] = 0
			if j + y < n:
				c[j + y] = 0
		j += 1
	j = 0
	while j < n:
		if j + y < n and j - y >= 0:
			r = c[j - y] | c[j + y]
		elif j + y < n:
			r = c[j + y]
		elif j - y >= 0:
			r = c[j - y]
		else:
			r = 0
		if r != b[j]:
			f = 1
			break
		j += 1
	if f == 1:
		print(-1)
	else:
		s = ''
		for j in c:
			s += str(j)
		print(s)


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	res = True
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			check = 2
			if i - x >= 0 and w[i - x] == '0' or i - x < 0:
				check -= 1
			if i + x < len(s) and w[i + x] == '0' or i + x >= len(s):
				check -= 1
			if not check:
				res = False
				break
	if res:
		w = ''.join(w)
		print(w)
	else:
		print(-1)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	a = ip().strip()
	x = int(ip())
	n = len(a)
	ans = ['1'] * n
	for i in range(n):
		val = a[i]
		if val == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	reconstruct = ['0'] * n
	flag = True
	for i in range(n):
		if i - x >= 0 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
			reconstruct[i] = '1'
		if not a[i] == reconstruct[i]:
			flag = False
			break
	if flag:
		print(*ans, sep='')
	else:
		print('-1')


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	arr = ['-1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				arr[i - x] = '0'
			if i + x < n:
				arr[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			flag1 = 0
			flag2 = 0
			if i - x >= 0:
				if arr[i - x] == '-1':
					flag1 = 1
			if i + x < n:
				if arr[i + x] == '-1':
					flag2 = 1
			if flag1 == 0 and flag2 == 0:
				print(-1)
				break
	else:
		string = ''
		for i in arr:
			if i == '0':
				string += '0'
			else:
				string += '1'
		print(string)


t = int(input())

def foo(s, x):
	n = len(s)
	y = n * ['1']
	for i in range(n - x):
		if s[i] == '0':
			y[i + x] = '0'
		if s[n - 1 - i] == '0':
			y[n - 1 - i - x] = '0'
	for i in range(n):
		if i - x >= 0 and y[i - x] == '1' or (i + x < n and y[i + x] == '1'):
			if s[i] == '0':
				return '-1'
		elif s[i] == '1':
			return '-1'
	return ''.join(y)
for _ in range(t):
	s = input()
	x = int(input())
	print(foo(s, x))


cases = int(input())
for _ in range(cases):
	string = input()
	x = int(input())
	originalString = ['1'] * len(string)
	for i in range(len(string)):
		if string[i] == '0':
			if i - x >= 0:
				originalString[i - x] = '0'
			if i + x < len(string):
				originalString[i + x] = '0'
	for i in range(len(string)):
		if string[i] == '1':
			if i - x >= 0 and originalString[i - x] == '1' or (i + x < len(string) and originalString[i + x] == '1'):
				continue
			else:
				print(-1)
				break
	else:
		print(''.join(originalString))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	s = [i for i in input() if i != '\n']
	x = int(input())
	ans = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = 0
			if i + x < len(s):
				ans[i + x] = 0
	ok = False
	for i in range(len(s)):
		if s[i] == '1':
			(ok1, ok2) = (False, False)
			if i >= x:
				if ans[i - x] == 1:
					ok1 = True
			if i + x < len(s):
				if ans[i + x] == 1:
					ok2 = True
			if not ok1 and (not ok2):
				print(-1)
				ok = True
				break
	if not ok:
		ans = ''.join(map(str, ans))
		sys.stdout.write(ans + '\n')


import math, queue, heapq
import sys
sys.setrecursionlimit(10 ** 6)
fastinput = sys.stdin.readline
fastout = sys.stdout.write
t = int(fastinput())
while t:
	t -= 1
	s = input()
	x = int(fastinput())
	w = ['1'] * len(s)
	n = len(s)
	ans = True
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x <= n - 1:
				w[i + x] = '0'
	result = ['0'] * n
	for i in range(n):
		if i - x >= 0 and w[i - x] == '1':
			result[i] = '1'
		elif i + x <= n - 1 and w[i + x] == '1':
			result[i] = '1'
	if ''.join(result) == s:
		print(''.join(w))
	else:
		print(-1)


T = int(input())
for _ in range(T):
	S = input()
	X = int(input())
	N = len(S)
	w = ['1'] * N
	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'
	flag = 1
	for i in range(N):
		char = '0'
		if i - X >= 0 and w[i - X] == '1':
			char = '1'
		if i + X < N and w[i + X] == '1':
			char = '1'
		if S[i] != char:
			flag = 0
			break
	if flag:
		print(''.join(w))
	else:
		print('-1')


def stringmaker(string1, x):
	finder = ['1'] * len(string1)
	output = ''
	for i in range(len(string1)):
		if string1[i] == '0':
			if i - x >= 0:
				finder[i - x] = '0'
			if i + x < len(string1):
				finder[i + x] = '0'
	for i in range(len(string1)):
		flag = 0
		output += finder[i]
		if string1[i] == '1':
			if i - x >= 0:
				if finder[i - x] == '0':
					flag += 1
			else:
				flag += 1
			if i + x < len(string1):
				if finder[i + x] == '0':
					flag += 1
			else:
				flag += 1
			if flag == 2:
				return -1
	return output
for i in range(int(input())):
	string1 = str(input())
	x = int(input())
	output = stringmaker(string1, x)
	print(output)


def check_strings(string, string2, k):
	result = True
	for index in range(len(string2)):
		selected_char = int(string[index])
		left_char = None
		right_char = None
		char_to_use = 0
		if index - k >= 0:
			left_char = string2[index - k]
		if index + k < len(string):
			right_char = string2[index + k]
		if left_char != None and left_char == 1 or (right_char != None and right_char == 1):
			char_to_use = 1
		if selected_char != char_to_use:
			result = False
			break
	return result

def make_string(string, k):
	result = -1
	new_string = []
	for elem in string:
		new_string.append(1)
	for index in range(len(string)):
		elem = int(string[index])
		if elem == 0:
			left_index = index - k
			right_index = index + k
			if left_index >= 0:
				new_string[left_index] = 0
			if right_index < len(string):
				new_string[right_index] = 0
	cres = check_strings(string, new_string, k)
	if cres == True:
		for index in range(len(new_string)):
			digit = new_string[index]
			new_string[index] = str(digit)
		result = ''.join(new_string)
	return result
ammount = int(input())
for index in range(ammount):
	string = str(input())
	k = int(input())
	cres = make_string(string, k)
	print(cres)


def dfs(s1, s, x, index, visited):
	orig = index
	while index < len(s):
		visited.add(index)
		if s[index] == '0':
			if index - x >= 0:
				s1[index - x] = '0'
			if index + x < len(s):
				s1[index + x] = '0'
		index += 1
	index = orig
	while index < len(s):
		if s[index] == '1':
			if index - x >= 0:
				if s1[index - x] == -1:
					s1[index - x] = '1'
			if index + x < len(s):
				if s1[index + x] == -1:
					s1[index + x] = '1'
		index += 1

def good(s1, s, x):
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s) and s1[i + x] != '0':
				return False
			if i - x >= 0 and s1[i - x] != '0':
				return False
		elif (i + x < len(s) and s1[i + x] != '1' or i + x >= len(s)) and (i - x >= 0 and s1[i - x] != '1' or i - x < 0):
			return False
	return True

def solve(s, x, ans):
	s1 = [-1] * len(s)
	visited = set()
	for i in range(len(s)):
		if i not in visited:
			dfs(s1, s, x, i, visited)
	for i in range(len(s)):
		if s1[i] == -1:
			s1[i] = '1'
	if good(s1, s, x):
		ans.append(s1)
	else:
		ans.append(['-1'])

def main():
	t = int(input())
	ans = []
	for i in range(t):
		s = input()
		x = int(input())
		solve(s, x, ans)
	for i in ans:
		print(''.join(i))
main()


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				w[i + x] = '0'
			if i - x >= 0:
				w[i - x] = '0'
	for i in range(n):
		t = i + x < n and w[i + x] == '1' or (i - x >= 0 and w[i - x] == '1')
		c = '0'
		if t:
			c = '1'
		if s[i] != c:
			print(-1)
			break
	else:
		print(''.join(w))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
from functools import lru_cache

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	S = input()
	x = int(input())
	Ans = {}
	n = len(S)
	f = 0
	for i in range(n):
		if S[i] == '0':
			Ans[i - x] = 0
			Ans[i + x] = 0
	stri = ''
	for i in range(n):
		stri += str(Ans.get(i, 1))
	for i in range(n):
		if S[i] == '1':
			g = 0
			if i - x >= 0:
				if stri[i - x] == '1':
					g = 1
			if i + x < n:
				if stri[i + x] == '1':
					g = 1
			if g == 0:
				f = 1
				break
	if f:
		print(-1)
	else:
		print(stri)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	n = len(s)
	s1 = ['1'] * n
	flag = 0
	for j in range(n):
		if s[j] == '0':
			if j - x >= 0:
				s1[j - x] = '0'
			if j + x < n:
				s1[j + x] = '0'
	for j in range(n):
		if s[j] == '1':
			flag = 1
			if j - x >= 0:
				if s1[j - x] != '0':
					s1[j - x] = '1'
					flag = 0
			if j + x < n:
				if s1[j + x] != '0':
					s1[j + x] = '1'
					flag = 0
			if flag == 1:
				break
	if flag == 1:
		print(-1)
	else:
		print(''.join(s1))


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	a = [int(i) for i in S()]
	x = I()
	n = len(a)
	s = [-1] * n
	flg = True
	for i in range(n):
		if a[i] == 1:
			if (i - x < 0 or s[i - x] == 0) and (i + x >= n or s[i + x] == 0):
				flg = False
				break
			if i - x < 0 or s[i - x] == 0:
				s[i + x] = 1
			else:
				s[i - x] = 1
		else:
			if i - x >= 0 and s[i - x] == 1 or (i + x < n and s[i + x] == 1):
				flg = False
				break
			if i - x >= 0:
				s[i - x] = 0
			if i + x < n:
				s[i + x] = 0
	if flg:
		print(*[1 if i else 0 for i in s], sep='')
	else:
		print(-1)


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	s = sys.stdin.readline().strip()
	x = int(sys.stdin.readline().strip())
	n = len(s)
	A = [1 for i in range(0, n)]
	for i in range(0, n):
		if i - x >= 0:
			if s[i - x] == '0':
				A[i] = 0
		if i + x < n:
			if s[i + x] == '0':
				A[i] = 0
	v = True
	for i in range(0, n):
		if s[i] == '1':
			w = False
			if i - x >= 0:
				if A[i - x] == 1:
					w = True
			if i + x < n:
				if A[i + x] == 1:
					w = True
			if w == False:
				v = False
		if s[i] == '0':
			w = True
			if i - x >= 0:
				if A[i - x] == 1:
					w = False
			if i + x < n:
				if A[i + x] == 1:
					w = False
			if w == False:
				v = False
	if v == False:
		print(-1)
	else:
		print(''.join(list(map(str, A))))


for t in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	flag = 0
	w = ['1'] * len(s)
	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'
	ws = ['0'] * n
	for i in range(n):
		if w[i] == '1':
			if i - x >= 0:
				ws[i - x] = '1'
			if i + x < n:
				ws[i + x] = '1'
	s = list(s)
	if s == ws:
		print(''.join(w))
	else:
		print(-1)


def solve():
	s = input()
	x = int(input())
	news = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				news[i + x] = '0'
			if i - x >= 0:
				news[i - x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			found = False
			if i + x < len(s) and news[i + x] == '1':
				found = True
			if i - x >= 0 and news[i - x] == '1':
				found = True
			if not found:
				return False
	return news
for _ in range(int(input())):
	res = solve()
	if res:
		print(''.join(res))
	else:
		print(-1)


def solve():
	t = int(input().strip())
	for i in range(t):
		s = [int(x) for x in input().strip()]
		x = int(input())
		n = len(s)
		w = ['1'] * n
		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'
		s_new = []
		for i in range(n):
			if i - x >= 0 and w[i - x] == '1':
				s_new.append(1)
			elif i + x < n and w[i + x] == '1':
				s_new.append(1)
			else:
				s_new.append(0)
		if s_new == s:
			print(''.join(w))
		else:
			print('-1')
solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
for _ in range(int(input())):
	s = input()
	x = int(input())
	f = 0
	n = len(s)
	ss = '1' * n
	ss = list(ss)
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ss[i - x] = '0'
			if i + x < n:
				ss[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and ss[i - x] == '1' or (i + x < n and ss[i + x] == '1'):
				pass
			else:
				f = 1
				break
		else:
			if i - x >= 0 and ss[i - x] != '0':
				f = 1
				break
			if i + x < n and ss[i + x] != '0':
				f = 1
				break
	print(''.join(ss) if f == 0 else -1)


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				w[i + x] = '0'
			if i - x > -1:
				w[i - x] = '0'
	check = ['0'] * n
	for i in range(n):
		if i - x > -1 and w[i - x] == '1':
			check[i] = '1'
		elif i + x < n and w[i + x] == '1':
			check[i] = '1'
	ans = ''.join(check)
	if s == ans:
		print(''.join(w))
	else:
		print(-1)


import math
from collections import deque
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < abs(max_ending_here):
			max_so_far = max_ending_here
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	s = input()
	s1 = ''
	x = int(input())
	l = ['1' for i in range(0, len(s))]
	n = len(s)
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			if i + x < n:
				l[i + x] = '0'
			if i - x >= 0:
				l[i - x] = '0'
	l1 = ['0' for i in range(0, n)]
	for i in range(0, n):
		if l[i] == '1':
			if i + x < n:
				l1[i + x] = '1'
			if i - x >= 0:
				l1[i - x] = '1'
	s2 = ''
	for i in range(0, n):
		s2 += l1[i]
	if s == s2:
		for i in range(0, n):
			print(l[i], end='')
		print()
	else:
		print(-1)
t = int(input())
for i in range(0, t):
	main()


t = int(input())
for j in range(t):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	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'
	p = [-1] * n
	for i in range(n):
		if i >= x and w[i - x] == '1':
			p[i] = '1'
		elif i + x < n and w[i + x] == '1':
			p[i] = '1'
		else:
			p[i] = '0'
	s1 = ''
	for i in p:
		s1 += i
	if s1 != s:
		print(-1, end='')
	else:
		for i in w:
			print(i, end='')
	print()


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	s2 = ['0'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if i >= x and w[i - x] == '1':
			s2[i] = '1'
		if i + x < n and w[i + x] == '1':
			s2[i] = '1'
	print(''.join(w)) if ''.join(s2) == s else print(-1)


for _ in range(int(input())):
	(s, x) = (list(map(int, input())), int(input()))
	n = len(s)
	new = [1] * n
	for i in range(n):
		if s[i] == 0:
			if i >= x:
				new[i - x] = 0
			if i + x < n:
				new[i + x] = 0
	w = []
	for i in range(n):
		temp = 0
		if i >= x:
			if new[i - x] == 1:
				temp = 1
		if i + x < n:
			if new[i + x] == 1:
				temp = 1
		w.append(temp)
	if w != s:
		print(-1)
	else:
		print(''.join(map(str, new)))


def multiple_input():
	return map(int, input().split())

def list_input():
	return list(map(int, input().split()))
for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	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'
	flag = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
				continue
			else:
				flag = 1
				break
	if flag == 0:
		print(*w, sep='')
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	out = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				out[i - x] = '0'
			if i + x < n:
				out[i + x] = '0'
	broke = False
	i = 0
	while i < n and (not broke):
		if s[i] == '1':
			if i - x >= 0 and out[i - x] == '1' or (i + x < n and out[i + x] == '1'):
				pass
			else:
				broke = True
				break
		i += 1
	if broke:
		print(-1)
	else:
		print(''.join(out))


t = int(input())
for i in range(t):
	s = list(input())
	x = int(input())
	temp = [1 for j in range(len(s))]
	for j in range(len(s)):
		if s[j] == '0':
			if j + x < len(s):
				temp[j + x] = 0
			if j - x >= 0:
				temp[j - x] = 0
	flag = 0
	for j in range(len(s)):
		if s[j] == '1':
			if j + x < len(s) and temp[j + x] == 1 or (j - x >= 0 and temp[j - x] == 1):
				continue
			else:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		print(*temp, sep='')


t = int(input())
while t:
	s = input()
	x = int(input())
	n = len(s)
	l1 = ['2' for i in range(0, n)]
	check = 0
	for i in range(0, n):
		if i + x < n and i - x > -1:
			if s[i] == '0':
				if l1[i - x] == '1' or l1[i + x] == '1':
					check = 1
					break
				else:
					l1[i - x] = '0'
					l1[i + x] = '0'
			elif l1[i - x] != '0' or l1[i + x] != '0':
				if l1[i - x] != '0':
					l1[i - x] = '1'
				elif l1[i + x] != '0':
					l1[i + x] = '1'
			else:
				check = 1
				break
		elif i + x < n:
			if l1[i + x] == '2':
				l1[i + x] = s[i]
			elif l1[i + x] != s[i]:
				check = 1
				break
		elif i - x > -1:
			if l1[i - x] == '2':
				l1[i - x] = s[i]
			elif l1[i - x] != s[i]:
				check = 1
				break
		elif s[i] == '1':
			check = 1
			break
	if check:
		print(-1)
	else:
		for i in range(0, n):
			if l1[i] == '2':
				l1[i] = '1'
		w = ''
		w = w.join(l1)
		print(w)
	t = t - 1


import sys

def i():
	return sys.stdin.readline()[:-1]

def getOutList(n, x, binList):
	outList = [False] * n
	for b in range(n - x):
		outList[b] = binList[b + x]
	for b in range(x, n):
		outList[b] = outList[b] or binList[b - x]
	return outList
cases = int(i())
for a in range(cases):
	inStr = i()
	binList = list((x == '1' for x in inStr))
	x = int(i())
	n = len(binList)
	posIn = [True] * n
	for b in range(n - x):
		if not binList[b]:
			posIn[b + x] = False
	for b in range(x, n):
		if not binList[b]:
			posIn[b - x] = False
	if not getOutList(n, x, posIn) == binList:
		print(-1)
	else:
		outStr = ''
		for bit in posIn:
			outStr += '1' if bit else '0'
		print(outStr)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for z in range(n):
		if s[z] == '0':
			if z - x >= 0:
				ans[z - x] = '0'
			if z + x < n:
				ans[z + x] = '0'
	c = 0
	for z in range(n):
		if s[z] == '1':
			c = 0
			v = z - x >= 0 and ans[z - x] == '1' or (z + x < n and ans[z + x] == '1')
			if not v:
				print(-1)
				c = 1
				break
	if c == 0:
		print(''.join(ans))


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	n = len(s)
	b = True
	l = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				l[i + x] = '0'
			if i - x >= 0:
				l[i - x] = '0'
	w = ''.join(l)
	l = ['0' for i in range(n)]
	for i in range(n):
		if i + x < n:
			if w[i + x] == '1':
				l[i] = '1'
		if i - x >= 0:
			if w[i - x] == '1':
				l[i] = '1'
	r = ''.join(l)
	if r == s:
		print(w)
	else:
		print(-1)


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)
threading.stack_size(2 ** 27)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		s = input()
		x = int(input())
		ans = ['1'] * len(s)
		for i in range(len(s)):
			if s[i] == '0':
				if i - x >= 0:
					ans[i - x] = '0'
				if i + x < len(s):
					ans[i + x] = '0'
		temp = ''
		for i in range(len(s)):
			if i - x >= 0 and ans[i - x] == '1':
				temp += '1'
			elif i + x < len(s) and ans[i + x] == '1':
				temp += '1'
			else:
				temp += '0'
		if s != temp:
			print(-1)
		else:
			print(''.join(ans))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	ntests = int(input())
	S = []
	W = []
	x = []
	for i in range(ntests):
		S.append(list(input()))
		x.append(int(input()))
		W.append(['X' for x in range(len(S[i]))])
	for i in range(ntests):
		m = []
		for letter in range(len(S[i])):
			left = bounds(letter - x[i], len(W[i]))
			right = bounds(letter + x[i], len(W[i]))
			if left and (not right):
				if not adjust(W[i], S[i][letter], letter - x[i]):
					break
			if right and (not left):
				if not adjust(W[i], S[i][letter], letter + x[i]):
					break
			if right and left:
				if S[i][letter] == '0':
					if not adjust(W[i], S[i][letter], letter + x[i]) or not adjust(W[i], S[i][letter], letter - x[i]):
						break
				else:
					m.append((letter + x[i], letter - x[i]))
			if not left and (not right) and (S[i][letter] == '1'):
				W[i] = '-1'
				break
		for pair in m:
			if W[i] == list('-1'):
				break
			if conflict(W[i], pair[0], pair[1]):
				W[i] = list('-1')
				break
	for word in range(len(W)):
		for letter in range(len(W[word])):
			if W[word][letter] == 'X':
				W[word][letter] = '1'
	for word in W:
		print(''.join(word))

def adjust(W, adjustment, position):
	if W[position] != 'X':
		if W[position] != adjustment:
			W[:] = '-1'
			return False
	W[position] = adjustment
	return True

def conflict(word, pos1, pos2):
	if word[pos1] == '0' and word[pos2] == '0':
		return True
	else:
		return False

def bounds(testcase, upperlimit, lowerlimit=0):
	if testcase >= lowerlimit and testcase < upperlimit:
		return True
	else:
		return False
main()


dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

def solve(s, x):
	ans = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < len(s):
				ans[i + x] = 0
	work = True
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == 1:
				continue
			if i + x < len(s) and ans[i + x] == 1:
				continue
			work = False
	if work:
		print(''.join(map(str, ans)))
	else:
		print(-1)
t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	solve(s, x)


for t in range(int(input())):
	s = list(input())
	n = len(s)
	d = ['1'] * n
	x = int(input())
	flag = False
	for (i, j) in enumerate(s):
		if j == '0':
			if i + x < n:
				d[i + x] = '0'
			if i - x >= 0:
				d[i - x] = '0'
	for (i, j) in enumerate(s):
		if j == '1':
			b1 = int(d[i - x]) if i - x >= 0 else 0
			b2 = int(d[i + x]) if i + x < n else 0
			if b1 + b2 == 0:
				flag = True
				break
	if flag:
		print(-1)
	else:
		print(''.join(d))


import sys

def rl(proc=None):
	if proc is not None:
		return proc(sys.stdin.readline())
	else:
		return sys.stdin.readline().rstrip()

def srl(proc=None):
	if proc is not None:
		return list(map(proc, rl().split()))
	else:
		return rl().split()

def solve(s, x):
	n = len(s)
	w = [1] * n
	for (i, v) in enumerate(s):
		if v == 0:
			if i - x >= 0:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	for (i, v) in enumerate(s):
		r = 0
		if i - x >= 0:
			r |= w[i - x]
		if i + x < n:
			r |= w[i + x]
		if r != v:
			return [-1]
	return w

def main():
	T = rl(int)
	for t in range(1, T + 1):
		s = list(map(int, rl()))
		x = rl(int)
		print(''.join(map(str, solve(s, x))))
main()


t = int(input())
for t_ in range(t):
	s = input()
	n = len(s)
	x = int(input())
	w = list('1' * n)
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				w[i + x] = '0'
			if i - x >= 0:
				w[i - x] = '0'
	flag = False
	for i in range(n):
		if s[i] == '1':
			if not (i + x < n and w[i + x] == '1') and (not (i - x >= 0 and w[i - x] == '1')):
				flag = True
				break
	if flag == False:
		print(''.join(w))
	else:
		print(-1)


def controller(s, x):
	n = len(s)
	w = [True] * n
	a = -x
	b = x
	for si in s:
		if si == '0':
			if a >= 0:
				w[a] = False
			if b < n:
				w[b] = False
		a += 1
		b += 1
	a = -x
	b = x
	for si in s:
		if si == '1':
			if a < 0:
				if b < n:
					if not w[b]:
						return '-1'
				else:
					return '-1'
			elif not w[a]:
				if b < n:
					if not w[b]:
						return '-1'
				else:
					return '-1'
		a += 1
		b += 1
	return ''.join(('1' if i else '0' for i in w))

def c_in():
	n_test_case = int(input())
	for i in range(n_test_case):
		s = input().rstrip()
		x = int(input())
		print(controller(s, x))
c_in()


def solve(s, x, n, w):
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			works = False
			if i >= x:
				if w[i - x] == '1':
					works = True
			if i + x < n:
				if w[i + x] == '1':
					works = True
			if not works:
				return -1
	return ''.join(w)
t = int(input())
for t in range(t):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1' for i in range(n)]
	result = solve(s, x, n, w)
	print(result)


def controller(s, x):
	n = len(s)
	s = tuple((i == '1' for i in s))
	w = [None] * n
	constraints = []
	for (i, si) in enumerate(s):
		a = i - x
		b = i + x
		has_a = 0 <= a
		has_b = b < n
		if has_a:
			if has_b:
				if si:
					constraints.append(i)
				else:
					if w[a] is None:
						w[a] = False
					elif w[a] is True:
						return -1
					if w[b] is None:
						w[b] = False
					elif w[b] is True:
						return -1
			elif w[a] is None:
				w[a] = si
			elif w[a] is not si:
				return -1
		elif has_b:
			if w[b] is None:
				w[b] = si
			elif w[b] is not si:
				return -1
		elif si:
			return -1
	for i in constraints:
		a = w[i - x]
		b = w[i + x]
		if a is True or b is True:
			pass
		elif a is False and b is False:
			return -1
	return ''.join(('0' if i is False else '1' for i in w))

def c_in():
	import sys
	file = sys.stdin
	n_test_case = int(file.readline())
	for i in range(n_test_case):
		s = file.readline().rstrip()
		x = int(file.readline())
		print(controller(s, x))
c_in()


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		x = int(input())
		n = len(s)
		w = ['1'] * n
		for i in range(n):
			if i + x < n:
				if s[i + x] == '0':
					w[i] = '0'
			if i - x >= 0:
				if s[i - x] == '0':
					w[i] = '0'
		ok = True
		for i in range(n):
			if s[i] == '0':
				if i + x < n:
					if w[i + x] == '1':
						ok = False
						break
				if i - x >= 0:
					if w[i - x] == '1':
						ok = False
						break
			else:
				if i + x < n and i - x >= 0:
					if w[i + x] == '0' and w[i - x] == '0':
						ok = False
						break
				if i + x >= n and i - x >= 0:
					if w[i - x] == '0':
						ok = False
						break
				if i + x < n and i - x < 0:
					if w[i + x] == '0':
						ok = False
						break
				if i + x >= n and i - x < 0:
					ok = False
					break
		print(''.join(w) if ok else -1)
	return
main()


for _ in range(int(input())):
	s = input()
	k = int(input())
	l = len(s)
	ans = [1] * l
	for i in range(l):
		if s[i] == '0':
			if i + k < l:
				ans[i + k] = 0
			if i - k >= 0:
				ans[i - k] = 0
	f = True
	for i in range(l):
		if s[i] == '1':
			if i - k >= 0 and ans[i - k] == 1 or (i + k < l and ans[i + k] == 1):
				f = True
			else:
				f = False
				break
	print(-1 if not f else ''.join((str(i) for i in ans)))


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	ok = True
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		one = False
		one = one | (i > x - 1 and ans[i - x] == '1')
		one = one | (i + x < n and ans[i + x] == '1')
		if one:
			l = '1'
		else:
			l = '0'
		if s[i] != l:
			ok = False
	if ok:
		print(''.join(ans))
	else:
		print(-1)


def solve(s, x):
	n = len(s)
	a = [None] * n
	todos = []
	for (i, c) in enumerate(s):
		if i <= x - 1:
			if i + x < n:
				if a[i + x] == None:
					a[i + x] = int(c)
				elif int(c) != a[i + x]:
					return -1
			elif c == '1':
				return -1
		elif i >= n - x:
			if i - x >= 0:
				if a[i - x] == None:
					a[i - x] = int(c)
				elif int(c) != a[i - x]:
					return -1
			elif c == '1':
				return -1
		elif c == '0':
			if a[i - x] == 1 or a[i + x] == 1:
				return -1
			a[i - x] = 0
			a[i + x] = 0
		else:
			todos.append((i - x, i + x))
	for (i, j) in todos:
		if a[i] == 0 and a[j] == 0:
			return -1
	for i in range(n):
		if a[i] == None:
			a[i] = 1
	return ''.join((str(x) for x in a))
tn = int(input())
for ti in range(tn):
	s = input()
	x = int(input())
	ans = solve(s, x)
	print(ans)


a = int(input())
for i in range(a):
	s = input()
	ans = []
	flag = 1
	for i in range(len(s)):
		ans.append(s[i])
	x = int(input())
	te = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				te[i - x] = 0
			if i + x < len(s):
				te[i + x] = 0
		else:
			a1 = 0
			if i - x >= 0 and te[i - x] == 0:
				a1 += 1
			if i + x < len(s) and te[i + x] == 0:
				a1 += 1
			if a1 == 2:
				flag = 0
				break
	for i in range(len(te)):
		if s[i] == '1':
			a1 = 0
			if i + x < len(te):
				if te[i + x] == 1:
					a1 += 1
			if i - x >= 0:
				if te[i - x] == 1:
					a1 += 1
			if a1 == 0:
				flag = 0
				break
	if flag == 0:
		print(-1)
	else:
		print(''.join(map(str, te)))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input()[:-1]
	x = int(input())
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < len(s):
				ans[i + x] = '0'
	F = True
	for i in range(len(s)):
		if s[i] == '1':
			f = False
			if i - x >= 0 and ans[i - x] == '1':
				f = True
			if i + x < len(s) and ans[i + x] == '1':
				f = True
			F &= f
	if F:
		print(''.join(ans))
	else:
		print(-1)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	a = [int(x) for x in input()]
	n = len(a)
	x = inn()
	ans = [-1] * n
	for i in range(n):
		if a[i] == 0:
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	valid = True
	for i in range(n):
		if a[i] == 1:
			valid1 = True
			valid2 = True
			in1 = False
			in2 = False
			if i - x >= 0:
				in1 = True
				if ans[i - x] == 0:
					valid1 = False
				else:
					ans[i - x] = 1
			if i + x < n:
				in2 = True
				if ans[i + x] == 0:
					valid2 = False
				else:
					ans[i + x] = 1
			if (not valid1 or in1 == False) and (not valid2 or in2 == False):
				valid = False
				break
	if valid:
		for i in range(n):
			if ans[i] == -1:
				ans[i] = 1
		print(*ans, sep='')
	else:
		print(-1)


def main():
	for _ in range(Iint()):
		s = list(map(int, input()))
		x = Iint()
		n = len(s)
		w = [1 for i in s]
		for i in range(n):
			if s[i] == 0:
				if i >= x:
					w[i - x] = 0
				if i + x < len(s):
					w[i + x] = 0
		newString = []
		for i in range(n):
			temp = 0
			if i >= x and w[i - x] == 1:
				temp = 1
			if i + x < len(s) and w[i + x] == 1:
				temp = 1
			newString.append(temp)
		if newString == s:
			Plist(w)
		else:
			print(-1)

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=''):
	print(s.join(map(str, li)))
main()


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
t = ip()
while t:
	t -= 1
	w = sip()
	x = ip()
	n = len(w) - 1
	arr = [2] * n
	flag = 0
	for i in range(n):
		if w[i] == '0':
			if i + x < n:
				if arr[i + x] == 2:
					arr[i + x] = 0
			if i - x >= 0:
				if arr[i - x] == 2:
					arr[i - x] = 0
				elif arr[i - x] == 1:
					flag = 1
					break
		else:
			check = 0
			if i - x >= 0:
				if arr[i - x] == 2:
					arr[i - x] = 1
				elif arr[i - x] == 0:
					check += 1
			else:
				check += 1
			if i + x < n:
				if arr[i + x] == 2:
					if check == 1:
						arr[i + x] = 1
			else:
				check += 1
			if check == 2:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		for item in arr:
			if item == 2:
				print(1, end='')
			else:
				print(item, end='')
		print()


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()
for _ in range(int(input())):
	string = input()
	string1 = []
	for i in string:
		string1.append(int(i))
	x = int(input())
	n = len(string1)
	initial = [1] * n
	for i in range(n):
		if string1[i] == 0:
			if i >= x:
				initial[i - x] = 0
			if i + x < n:
				initial[i + x] = 0
	matching = []
	for i in range(n):
		v = 0
		if i >= x and initial[i - x] == 1:
			v = 1
		if i + x < n and initial[i + x] == 1:
			v = 1
		matching.append(v)
	if matching != string1:
		print(-1)
	else:
		an = ''
		for i in range(len(initial)):
			an += str(initial[i])
		print(an)


for i in range(0, int(input())):
	s = list(input())
	n = int(input())
	w = []
	for j in range(0, len(s)):
		w.append(1)
	for j in range(0, len(s)):
		if s[j] == '0':
			if j - n >= 0:
				w[j - n] = 0
			if j + n < len(s):
				w[j + n] = 0
	q = [0] * len(w)
	for j in range(0, len(w)):
		if j - n >= 0 and w[j - n] == 1:
			q[j] = 1
		elif j + n < len(s) and w[j + n] == 1:
			q[j] = 1
		else:
			q[j] = 0
	k = 0
	for j in range(0, len(s)):
		if int(s[j]) == q[j]:
			k += 1
	if k == len(s):
		print(''.join(map(str, w)))
	else:
		print('-1')


def solve(s, x):
	n = len(s)
	need_0 = set()
	for i in range(1, n + 1):
		if s[i - 1] == '0':
			if i - x > 0:
				need_0.add(i - x)
			if i + x <= n:
				need_0.add(i + x)
	w = ''
	for j in range(1, n + 1):
		if s[j - 1] == '1':
			back_test = j - x <= 0 or j - x in need_0
			front_test = j + x > n or j + x in need_0
			if back_test and front_test:
				return -1
	for k in range(1, n + 1):
		if k in need_0:
			w += '0'
		else:
			w += '1'
	return w

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		x = int(input())
		print(solve(s, x))
main()


t = int(input())
for g in range(0, t):
	s = list(input())
	a = []
	for i in range(0, len(s)):
		a.append(-1)
	x = int(input())
	ans = 1
	for i in range(0, len(s)):
		if s[i] == '0':
			if i + x < len(s):
				a[i + x] = '0'
			if i - x >= 0:
				a[i - x] = '0'
		else:
			done = 0
			if i - x >= 0:
				if a[i - x] == -1 or a[i - x] == '1':
					done = 1
					a[i - x] = '1'
			if i + x < len(s) and done == 0:
				if a[i + x] == -1:
					done = 1
					a[i + x] = '1'
			if done == 0:
				ans = 0
				break
	if ans == 0:
		print(-1)
	else:
		ans = 1
		for i in range(len(s)):
			if s[i] == '0':
				done = 1
				if i + x < len(s) and a[i + x] != '0':
					done = 0
				if i - x >= 0 and a[i - x] != '0':
					done = 0
				if done == 0:
					ans = 0
					break
			else:
				done = 0
				if i + x < len(s) and a[i + x] == '1':
					done = 1
				if i - x >= 0 and a[i - x] == '1':
					done = 1
				if done == 0:
					ans = 0
					break
		final = ''
		if ans == 0:
			print(-1)
		else:
			for i in range(0, len(s)):
				if a[i] == -1:
					a[i] = '1'
				final += a[i]
			print(final)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	s = input()
	n = len(s)
	x = int(input())
	ans = [''] * n
	for i in range(x):
		if i + x < n:
			ans[i + x] = max(ans[i + x], s[i])
	for i in range(n - 1, n - x - 1, -1):
		if i - x >= 0:
			ans[i - x] = max(ans[i - x], s[i])
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
		if ans[i] == '':
			ans[i] = '1'
	pos = True
	for i in range(n):
		b = '0'
		if i + x < n:
			b = max(b, ans[i + x])
		if i - x >= 0:
			b = max(b, ans[i - x])
		if s[i] == b:
			continue
		else:
			pos = False
			break
	if pos:
		print(*ans, sep='')
	else:
		print(-1)


import math
import sys
import collections

def In():
	return map(int, sys.stdin.readline().split())
input = sys.stdin.readline

def rob():

	def decide(amount, amount1, sma, big):

		def add(amount):
			nonlocal ans
			maxam = min(amount // l[pos][0], l[pos][1])
			ans += maxam
			amount -= l[pos][0] * maxam
			l[pos][1] -= maxam
			return amount
		l = [sma, big]
		pos = 0
		ans = 0
		amount = add(amount)
		if not l[pos][1]:
			pos += 1
		amount = add(amount)
		amount1 = add(amount1)
		return ans

	def solve(sma, big):
		return max(decide(p, f, sma, big), decide(f, p, sma, big))
	for _ in range(int(input())):
		(p, f) = In()
		(sw, ax) = In()
		(sww, axw) = In()
		if sww < axw:
			print(solve([sww, sw], [axw, ax]))
		else:
			print(solve([axw, ax], [sww, sw]))

def binarecon():
	for i in range(int(input())):
		s = input().rstrip()
		x = int(input())
		lens = len(s)
		must = [False] * lens
		for i in range(lens):
			if s[i] == '0':
				if i - x > -1:
					must[i - x] = True
				if i + x < lens:
					must[i + x] = True
		for i in range(lens):
			if s[i] == '1':
				yes = False
				if i - x > -1:
					yes = 1 - must[i - x]
				if i + x < lens:
					yes = max(yes, 1 - must[i + x])
				if not yes:
					print(-1)
					break
		else:
			for i in must:
				if not i:
					print(1, end='')
				else:
					print(0, end='')
			print()
binarecon()


for _ in range(int(input())):
	(s, x) = (list(map(int, input())), int(input()))
	n = len(s)
	r = [1] * n
	for i in range(n):
		if s[i] is 0:
			if i >= x:
				r[i - x] = 0
			if i + x < n:
				r[i + x] = 0
	w = []
	for i in range(n):
		b = 0
		if i >= x and r[i - x] == 1:
			b = 1
		if i < n - x and r[i + x] == 1:
			b = 1
		w.append(b)
	if w != s:
		print(-1)
	else:
		print(''.join(map(str, r)))


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	x = int(input())
	w = ['1'] * n
	S = ['0'] * n
	for (i, si) in enumerate(s):
		if si == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if i >= x and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			S[i] = '1'
	print(''.join(w) if s == ''.join(S) else '-1')


for _ in range(int(input())):
	s = list(input().strip())
	x = int(input())
	n = len(s)
	f = 0
	res = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				res[i - x] = '0'
			if i + x < n:
				res[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			done = 0
			if i - x >= 0 and res[i - x] != '0':
				res[i - x] = '1'
				done = 1
			if i + x < n and res[i + x] != '0':
				res[i + x] = '1'
				done = 1
			if not done:
				f = 1
	if f:
		print(-1)
	else:
		print(''.join(res))


t = int(input())
for _ in range(t):
	s = list(input())
	n = len(s)
	x = int(input())
	ans = [1] * n
	flag = 0
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				ans[x + i] = 0
			if i - x >= 0:
				ans[i - x] = 0
	res = [-1] * n
	for i in range(n):
		if i - x >= 0 and ans[i - x] == 1:
			res[i] = '1'
		elif i + x < n and ans[i + x] == 1:
			res[i] = '1'
		else:
			res[i] = '0'
	for i in range(n):
		if s[i] != res[i]:
			print(-1)
			flag = 1
			break
	if flag:
		continue
	print(*ans, sep='')


for _ in range(int(input())):
	s = list(input())
	x = int(input())
	n = len(s)
	w = ['1'] * n
	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'
	s_recreated = ['?'] * n
	for i in range(n):
		if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			s_recreated[i] = '1'
		else:
			s_recreated[i] = '0'
	if s_recreated == s:
		print(''.join(w))
	else:
		print('-1')


for _ in range(int(input())):
	s = input()
	x = int(input())
	s = ' ' + s
	prev = [0] * (len(s) + 1)
	prev[0] = -1
	prev[-1] = -1
	for i in range(1, len(s)):
		if s[i] == '0':
			prev[max(i - x, 0)] = -1
			prev[min(i + x, len(s))] = -1
	ok = True
	for i in range(1, len(s)):
		if s[i] == '1' and prev[max(i - x, 0)] == -1 and (prev[min(i + x, len(s))] == -1):
			print(-1)
			ok = False
			break
	if ok:
		for i in range(1, len(s)):
			print(prev[i] + 1, end='')
		print('')


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')

def maps():
	return [int(i) for i in input().split()]

def check(s, w, n, x):
	for i in range(n):
		ok = False
		if s[i] == '1':
			if i >= x and w[i - x] == '1':
				ok = True
			elif i + x < n and w[i + x] == '1':
				ok = True
		elif i - x < 0 and i + x >= n:
			ok = True
		elif i - x >= 0 and i + x < n:
			if w[i - x] == w[i + x] == '0':
				ok = True
		elif i >= x and w[i - x] == '0':
			ok = True
		elif i + x < n and w[i + x] == '0':
			ok = True
		if not ok:
			return False
	return True
for _ in range(*maps()):
	s = input()
	n = len(s)
	(x,) = maps()
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	if check(s, w, n, x):
		print(''.join(w))
	else:
		print('-1')


from sys import stdout

def function(inp, x):
	output = []
	n = len(inp)
	for i in range(n):
		pre_in = 0
		if i > 2 * x - 1:
			pre_in = inp[i - 2 * x]
		post_in = 0
		if i < n - 2 * x:
			post_in = inp[i + 2 * x]
		if inp[i] == '1' and (pre_in == '0' or i - x < 0) and (post_in == '0' or i + x >= n):
			return '-1'
		pre_in = None
		if i > x - 1:
			pre_in = inp[i - x]
		post_in = None
		if i < n - x:
			post_in = inp[i + x]
		if pre_in == '0' or post_in == '0':
			output.append('0')
		else:
			output.append('1')
	return ''.join(output)
total = int(input())
inp = None
for index in range(2 * total):
	line = input()
	if index % 2 == 0:
		inp = line
	else:
		x = int(line)
		result = function(inp, x)
		print(result)
	stdout.flush()


for _ in range(int(input())):
	s = list(map(int, input()))
	x = int(input())
	n = len(s)
	w = [1] * n
	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
	t = [1] * n
	for i in range(n):
		g = 0
		if i - x >= 0:
			if w[i - x] == 1:
				g += 1
		if i + x < n:
			if w[i + x] == 1:
				g += 1
		if g > 0:
			t[i] = 1
		else:
			t[i] = 0
	if s == t:
		print(''.join(map(str, w)))
	else:
		print(-1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().rstrip()
	x = int(input())
	n = len(s)
	ans = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			check = False
			if i - x >= 0:
				check |= ans[i - x] == '1'
			if i + x < n:
				check |= ans[i + x] == '1'
			if not check:
				print(-1)
				break
	else:
		print(''.join(ans))


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	s = input()[:-1]
	x = int(input())
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	F = True
	for i in range(len(s)):
		if s[i] == '1':
			flag = False
			if i + x < len(s) and ans[i + x] == '1':
				flag = True
			if i - x >= 0 and ans[i - x] == '1':
				flag = True
			F &= flag
	if not F:
		print(-1)
	else:
		print(''.join(ans))


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	s = input().strip('\n')
	x = int(input())
	n = len(s)
	w = [1] * n
	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
	s_ = [0] * n
	for i in range(n):
		if i - x >= 0 and w[i - x] == 1:
			s_[i] = 1
		elif i + x < n and w[i + x] == 1:
			s_[i] = 1
	flag = True
	for i in range(n):
		if s[i] != str(s_[i]):
			flag = False
			break
	if flag == False:
		print(-1)
	else:
		ans = ''
		for i in w:
			ans += str(i)
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()[:-1]
	x = int(input())
	n = len(s)
	ans = [1] * n
	for (i, char) in enumerate(s):
		if char == '0':
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	new_s = [1] * n
	for i in range(n):
		is_zero = True
		if i - x >= 0 and ans[i - x] == 1:
			is_zero = False
		if i + x < n and ans[i + x] == 1:
			is_zero = False
		if is_zero:
			new_s[i] = 0
	new_s = ''.join(map(str, new_s))
	if s == new_s:
		print(''.join(map(str, ans)))
	else:
		print(-1)


import sys
input = sys.stdin.readline
INF = 10

def solution():
	s = list(map(int, input().rstrip()))
	x = int(input())
	N = len(s)
	ans = [-1] * N
	flag = True
	for i in range(N):
		if i - x < 0:
			L = INF
		else:
			L = ans[i - x]
		if i + x >= N:
			R = INF
		else:
			R = ans[i + x]
		if s[i] == 1:
			if L == 1 or R == 1:
				continue
			elif L == -1:
				ans[i - x] = 1
			elif R == -1:
				ans[i + x] = 1
			else:
				flag = False
		if s[i] == 0:
			if L == 0 and R == 0:
				continue
			elif L != 1 and R != 1:
				if L == -1:
					ans[i - x] = 0
				if R == -1:
					ans[i + x] = 0
			else:
				flag = False
	if not flag:
		print(-1)
	else:
		for i in range(N):
			if ans[i] == -1:
				ans[i] = 1
		print(''.join(map(str, ans)))
T = int(input())
for _ in range(T):
	solution()


t = int(input())
while False:
	break
for i in range(t):
	s = input()
	n = len(s)
	xx = int(input())
	aa = 1000
	while False:
		break
	arrw = [0] * n
	for m in range(n):
		if m - xx < 0:
			if m + xx < n:
				arrw[m] = int(s[m + xx])
		elif m + xx >= n:
			if m - xx >= 0:
				arrw[m] = int(s[m - xx])
		else:
			while False:
				break
			arrw[m] = int(s[m - xx]) & int(s[m + xx])
	while False:
		break
	check = True
	for num in range(n):
		if num - xx < 0 and num + xx >= n:
			if s[num] == '1':
				check = False
				break
			continue
		aaa = 100
		if num - xx < 0:
			if int(s[num]) != arrw[num + xx]:
				while False:
					break
				check = False
				break
		elif num + xx >= n:
			if int(s[num]) != arrw[num - xx]:
				check = False
				break
		elif int(s[num]) != arrw[num - xx] | arrw[num + xx]:
			check = False
			break
	while False:
		break
	if check == True:
		disp = ''
		for num in range(n):
			disp += str(arrw[num])
		while False:
			break
		print(disp)
	else:
		print(-1)


import sys
from _collections import deque
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	a = input()
	n = len(a)
	x = int(input())
	b = [1] * n
	ans = 1
	for i in range(1, n + 1):
		if a[i - 1] == '0':
			if i + x <= n:
				b[i + x - 1] = 0
			if i > x:
				b[i - x - 1] = 0
	for i in range(1, n + 1):
		if a[i - 1] == '1':
			if i + x <= n and b[i + x - 1] or (i > x and b[i - x - 1]):
				continue
			else:
				ans = 0
				break
	if ans:
		for i in b:
			if i == 1:
				print(1, end='')
			else:
				print(0, end='')
		print()
	else:
		print(-1)


def get_int():
	return int(input())

def get_ints():
	return [int(x) for x in input().split()]
t = get_int()
for i in range(0, t):
	s = input()
	x = get_int()
	w = '0' * x + '?' * len(s) + '0' * x
	s = list(s)
	w = list(w)
	for j in range(0, len(s)):
		if s[j] == '0':
			w[j] = '0'
			w[j + 2 * x] = '0'
	for j in range(0, len(w)):
		if w[j] == '?':
			w[j] = '1'
	impossible = False
	for j in range(0, len(s)):
		if s[j] == '1':
			if w[j] == '0' and w[j + 2 * x] == '0':
				print('-1')
				impossible = True
				break
	if not impossible:
		print(''.join(w[x:x + len(s)]))


T = int(input())
for _ in range(0, T):
	s = input()
	x = int(input())
	L = ['1'] * len(s)
	n = len(s)
	for i in range(0, len(s)):
		if s[i] == '0':
			if i + x < n:
				L[i + x] = '0'
			if i - x >= 0:
				L[i - x] = '0'
	temp = ''.join(L)
	temp = str(temp)
	kk = ['0'] * len(s)
	for i in range(0, len(L)):
		tt = 0
		if i + x < n and L[i + x] == '1':
			tt = 1
		if i - x >= 0 and L[i - x] == '1':
			tt = 1
		if tt == 0:
			kk[i] = '0'
		else:
			kk[i] = '1'
	kk = ''.join(kk)
	kk = str(kk)
	if s == kk:
		print(temp)
	else:
		print(-1)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	s = ips()
	x = ip()
	n = len(s)
	ans = [None] * n
	flag = True
	for i in range(x):
		pos = i + x
		if pos < n:
			if ans[pos] == None:
				ans[pos] = s[i]
			elif ans[pos] != s[i]:
				flag = False
				break
	for i in range(n - x, n):
		pos = i - x
		if pos >= 0:
			if ans[pos] == None:
				ans[pos] = s[i]
			elif ans[pos] != s[i]:
				flag = False
				break
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				if ans[i + x] == None:
					ans[i + x] = '0'
				elif ans[i + x] == '0':
					pass
				else:
					flag = False
					break
			if i - x >= 0:
				if ans[i - x] == None:
					ans[i - x] = '0'
				elif ans[i - x] == '0':
					pass
				else:
					flag = False
					break
		if i - x < 0 and i + x >= n:
			if s[i] == '1':
				flag = False
				break
	if flag:
		for i in range(n):
			if ans[i] == None:
				ans[i] = '1'
		ans = ''.join(ans)
		ch = [None] * n
		for i in range(n):
			if i - x < 0 and i + x >= n:
				ch[i] = '0'
			else:
				if i - x >= 0:
					if ans[i - x] == '1':
						ch[i] = '1'
				if i + x < n:
					if ans[i + x] == '1':
						ch[i] = '1'
				if ch[i] == None:
					ch[i] = '0'
		ch = ''.join(ch)
		if s == ch:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for tt in range(t):
	s = input()
	n = len(s)
	x = int(input())
	ans = [1] * n
	f = int(1)
	for i in range(n):
		if ord(s[i]) == ord('0'):
			if i + x <= n - 1:
				ans[i + x] = 0
			if i - x >= 0:
				ans[i - x] = 0
	for i in range(n):
		if ord(s[i]) == ord('0'):
			if i + x <= n - 1:
				if ans[i + x] != 0:
					f = 0
					break
			if i - x >= 0:
				if ans[i - x] != 0:
					f = 0
					break
		elif ord(s[i]) == ord('1'):
			cc = int(2)
			if i + x <= n - 1:
				if ans[i + x] == 1:
					cc -= 1
			if i - x >= 0:
				if ans[i - x] == 1:
					cc -= 1
			if cc == 2:
				f = 0
				break
	if f:
		for i in range(n):
			print(ans[i], end='')
		print()
	else:
		print(-1)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for ii in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)

	def legal(a, n):
		return a >= 0 and a < n
	ans = ['1'] * n
	f = 1
	for i in range(n):
		if s[i] == '0':
			if legal(i - x, n):
				ans[i - x] = '0'
			if legal(i + x, n):
				ans[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			if legal(i - x, n) and ans[i - x] == '1':
				continue
			if legal(i + x, n) and ans[i + x] == '1':
				continue
			f = 0
	if f:
		print(''.join(ans))
	else:
		print(-1)


for _ in range(int(input())):
	flag = 1
	s = input()
	x = int(input())
	n = len(s)
	l = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0' and i + x < n:
			l[i + x] = '0'
		if s[i] == '0' and i - x >= 0:
			l[i - x] = '0'
	for i in range(n):
		if s[i] == '1':
			if x + i < n and l[i + x] == '1' or (i - x >= 0 and l[i - x] == '1'):
				continue
			else:
				print(-1)
				flag = 0
				break
	if flag:
		print(''.join(l))


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	s = [int(x) for x in input()]
	n = len(s)
	x = ri()
	w = [1] * n
	new_s = [-1] * n
	ans = 1
	for i in range(n):
		if s[i] == 0:
			if i - x >= 0:
				w[i - x] = 0
			if i + x <= n - 1:
				w[i + x] = 0
	for i in range(n):
		if i - x >= 0 and w[i - x] == 1 or (i + x <= n - 1 and w[i + x] == 1):
			new_s[i] = 1
		else:
			new_s[i] = 0
	for i in range(n):
		if new_s[i] != s[i]:
			ans = -1
			break
	if ans == -1:
		print(-1)
	else:
		print(''.join([str(x) for x in w]))


def solve(s, x):
	ans = [None] * len(s)
	for (i, char) in enumerate(s):
		if char == '0':
			if i + x < len(s):
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	for (i, char) in enumerate(s):
		if char == '1':
			if i + x < len(s) and ans[i + x] == '0' or i + x >= len(s):
				if i - x >= 0 and ans[i - x] is None:
					ans[i - x] = '1'
				elif i - x >= 0 and ans[i - x] == '0' or i - x < 0:
					return -1
			elif i - x >= 0 and ans[i - x] == '0' or i - x < 0:
				ans[i + x] = '1'
	for i in range(len(ans)):
		if ans[i] is None:
			ans[i] = '1'
	return ''.join(ans)
t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	print(solve(s, x))


def solution():
	s = list(input())
	x = int(input())
	n = len(s)
	flag = 0
	l = ['2'] * n
	for i in range(n):
		p = i - x
		q = i + x
		if p < 0 and q > n - 1:
			if s[i] == '1':
				flag = 1
				break
		elif p < 0:
			if s[i] == '1':
				if l[q] == '0':
					flag = 1
					break
				l[q] = '1'
			else:
				if l[q] == '1':
					flag = 1
					break
				l[q] = '0'
		elif q > n - 1:
			if s[i] == '1':
				if l[p] == '0':
					flag = 1
					break
				l[p] = '1'
			else:
				if l[p] == '1':
					flag = 1
					break
				l[p] = '0'
		elif s[i] == '0':
			if l[p] == '1' or l[q] == '1':
				flag = 1
				break
			l[p] = '0'
			l[q] = '0'
		elif l[p] == '0' and l[q] == '0':
			flag = 1
			break
		elif l[p] == '0' and l[q] == '2':
			l[q] = '1'
		elif l[p] == '2' and l[q] == '0':
			l[p] = '1'
	if flag:
		print(-1)
	else:
		ans = ''
		for i in range(n):
			if l[i] == '2':
				ans += '1'
			else:
				ans += l[i]
		print(ans)
t = int(input())
for _ in range(t):
	solution()


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())

def solve():
	s = input()
	n = len(s)
	x = int(input())
	d = [None] * n
	li = []
	for i in range(n):
		if i - x >= 0 and i + x < n:
			if s[i] == '0':
				if d[i - x] == 1 or d[i + x] == 1:
					print(-1)
					return
				d[i - x] = 0
				d[i + x] = 0
			else:
				li.append((i - x, i + x))
		elif i - x >= 0:
			if s[i] == '0':
				if d[i - x] == 1:
					print(-1)
					return
				d[i - x] = 0
			else:
				if d[i - x] == 0:
					print(-1)
					return
				d[i - x] = 1
		elif i + x < n:
			if s[i] == '0':
				if d[i + x] == 1:
					print(-1)
					return
				d[i + x] = 0
			else:
				if d[i + x] == 0:
					print(-1)
					return
				d[i + x] = 1
		elif s[i] == '1':
			print(-1)
			return
	for (a, b) in li:
		if d[a] == 0 and d[b] == 0:
			print(-1)
			return
		elif d[a] == 0:
			d[b] = 1
		elif d[b] == 0:
			d[a] = 1
		else:
			d[a] = 1
			d[b] = 1
	for i in range(n):
		if d[i] is None:
			d[i] = 1
	print(*d, sep='')
for _ in range(t):
	solve()


for idn in range(int(input())):
	s = [int(symbol) for symbol in input()]
	n = len(s)
	x = int(input())
	q = [1 for i in range(n)]
	for i in range(n):
		if x <= i and s[i] == 0:
			q[i - x] = 0
		if i + x < n and s[i] == 0:
			q[i + x] = 0
	for i in range(min(x, n - x)):
		q[i + x] = s[i]
		q[n - i - 1 - x] = s[n - i - 1]
	w = [0 for i in range(n)]
	for i in range(n):
		if x <= i:
			w[i] = w[i] | q[i - x]
		if i + x < n:
			w[i] = w[i] | q[i + x]
	if w == s:
		print(str(q)[1:-1].replace(', ', ''))
	else:
		print(-1)


t = int(input())
for i in range(t):
	ar = [str(i) for i in input()]
	n = len(ar)
	f = int(input())
	no = 0
	b = ['1'] * n
	for x in range(n):
		if ar[x] == '0':
			if x >= f:
				b[x - f] = '0'
			if x + f < n:
				b[x + f] = '0'
	for x in range(n):
		if ar[x] == '1':
			if (x >= f and b[x - f] == '0' or x < f) and (x + f < n and b[x + f] == '0' or x + f >= n):
				no = -1
				break
	if no == -1:
		print(no)
	else:
		print(''.join(b))


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))

def f(s, x):
	w = [None for _ in range(len(s))]
	for i in range(len(s)):
		if s[i] == '1':
			if i - x < 0 and i + x >= len(s):
				return -1
			try:
				if w[i - x] == '0' and w[i + x] == '0':
					return -1
			except:
				pass
			if i - x >= 0:
				if w[i - x] == '0':
					if i + x < len(s) and w[i + x] != '0':
						w[i + x] = '1'
					else:
						return -1
				elif w[i - x] == None:
					w[i - x] = '1'
					if len(s) > i + x >= len(s) - x:
						w[i + x] = '1'
			elif i + x < len(s):
				if w[i + x] == '0':
					return -1
				elif w[i + x] == None:
					w[i + x] = '1'
		else:
			if i - x >= 0:
				if w[i - x] == '1':
					return -1
				w[i - x] = '0'
			if i + x < len(s):
				if w[i + x] == '1':
					return -1
				w[i + x] = '0'
	for i in range(len(w)):
		if w[i] == None:
			w[i] = '0'
	return ''.join(w)
t = iinput()
while t:
	t -= 1
	s = input()
	x = iinput()
	print(f(s, x))


t = int(input())
while t > 0:
	s = input()
	x = int(input())
	n = len(s)

	def helper(n, s, x):
		w = '1' * n
		w = list(w)
		for i in range(n):
			if s[i] == '0':
				if i + x < n:
					w[i + x] = '0'
				if i - x >= 0:
					w[i - x] = '0'
		for i in range(n):
			if s[i] == '1':
				if i + x < n and w[i + x] == '1' or (i - x >= 0 and w[i - x] == '1'):
					continue
				else:
					return -1
			elif i + x < n and w[i + x] == '1' or (i - x >= 0 and w[i - x] == '1'):
				return -1
		return ''.join(w)
	print(helper(n, s, x))
	t -= 1


cases = int(input())
for t in range(cases):
	s = input()
	x = int(input())
	n = len(s)
	l = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				l[i - x] = '0'
			if i + x < n:
				l[i + x] = '0'
	ln = ['0'] * n
	for i in range(n):
		if i - x >= 0:
			if l[i - x] == '1':
				ln[i] = '1'
		if i + x < n:
			if l[i + x] == '1':
				ln[i] = '1'
	f = 0
	for i in range(n):
		if s[i] != ln[i]:
			f = 1
			break
	if f == 0:
		print(''.join(l))
	else:
		print(-1)


n = int(input())
for i in range(n):
	s = input()
	k = int(input())
	n1 = len(s)
	ans = ['1'] * n1
	for i in range(n1):
		if s[i] == '0':
			if i - k >= 0:
				ans[i - k] = '0'
			if i + k < n1:
				ans[i + k] = '0'
	for i in range(n1):
		if s[i] == '1':
			flag = 0
			if i - k >= 0 and ans[i - k] == '1':
				flag = 1
			if i + k < n1 and ans[i + k] == '1':
				flag = 1
			if flag == 0:
				print(-1)
				break
	else:
		print(str(''.join(ans)))


for q in range(int(input())):
	s = input()
	s = '2' + s
	x = int(input())
	n = len(s) - 1
	w = [2] * (n + 1)
	res = 1
	for i in range(1, n + 1):
		if s[i] == '1':
			if i > x:
				if i + x > n:
					if w[i - x] == 2:
						w[i - x] = 1
					elif w[i - x] == 0:
						res = 0
						break
				else:
					if w[i - x] == 0:
						if w[i + x] == 2:
							w[i + x] = 1
						elif w[i + x] == 0:
							res = 0
							break
					if w[i + x] == 0:
						if w[i - x] == 2:
							w[i - x] = 1
						elif w[i - x] == 0:
							res = 0
							break
			elif i + x > n:
				res = 0
				break
			elif w[i + x] == 2:
				w[i + x] = 1
			elif w[i + x] == 0:
				res = 0
				break
		else:
			if i > x:
				if w[i - x] == 2:
					w[i - x] = 0
				elif w[i - x] == 1:
					res = 0
					break
			if i + x <= n:
				if w[i + x] == 2:
					w[i + x] = 0
				elif w[i + x] == 1:
					res = 0
					break
	if res == 0:
		print(-1)
	else:
		for o in range(1, n + 1):
			if w[o] == 2:
				w[o] = 1
		print(*w[1:], sep='')


t = int(input())
while t > 0:
	t -= 1
	s = input()
	x = int(input())
	l = ['1'] * len(s)
	n = len(s)
	check = True
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				l[i - x] = '0'
			if i + x < n:
				l[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and l[i - x] == '1':
				continue
			elif i + x < n and l[i + x] == '1':
				continue
			else:
				print(-1)
				check = False
				break
	if check:
		print(''.join(l))


t = int(input())
for _ in range(t):
	ok = True
	txt = input().strip()
	n = int(input())
	ans = ['1' for c in txt]
	for i in range(len(txt)):
		if txt[i] == '0':
			if i - n >= 0:
				ans[i - n] = '0'
			if i + n < len(txt):
				ans[i + n] = '0'
	for i in range(len(txt)):
		if txt[i] == '1':
			if i - n >= 0 and ans[i - n] == '1':
				continue
			elif i + n < len(txt) and ans[i + n] == '1':
				continue
			else:
				ok = False
				break
	print(''.join(ans) if ok else -1)


for _ in range(int(input())):
	s = 'x' + input()
	n = len(s)
	x = int(input())
	w = ['1'] * n
	for i in range(1, n):
		if s[i] == '0':
			if i > x and i - x > 0 and (i - x < n):
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	ans = ''.join(w[1:])
	ss = ''
	for i in range(1, n):
		flag1 = flag2 = False
		if i > x and i - x > 0 and (i - x < n):
			if w[i - x] == '1':
				flag1 = True
		if i + x < n:
			if w[i + x] == '1':
				flag2 = True
		if not flag1 | flag2:
			ss += '0'
		else:
			ss += '1'
	if s[1:] == ss:
		print(ans)
	else:
		print(-1)


def fun(ans, s):
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == '1':
				continue
			if i + x < len(s) and ans[i + x] == '1':
				continue
			return False
	return True
for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	ret = ''.join(ans)
	chk = fun(ans, s)
	if not chk:
		print(-1)
	else:
		print(ret)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()

	def f(a, x):
		l = len(a)
		b = [0] * l
		for i in range(l):
			if i >= x and a[i - x] == 1:
				b[i] = 1
			elif i < l - x and a[i + x] == 1:
				b[i] = 1
		return b

	def g(a, x):
		l = len(a)
		b = [1] * l
		for i in range(l):
			if i >= x and a[i - x] == 0:
				b[i] = 0
			elif i < l - x and a[i + x] == 0:
				b[i] = 0
		return b
	rr = []
	for _ in range(t):
		s = S()
		x = I()
		a = [int(c) for c in s]
		b = g(a, x)
		c = f(b, x)
		if a != c:
			b = [-1]
		rr.append(JA(b, ''))
	return JA(rr, '\n')
print(main())


t = int(input())
for _ in range(t):
	st = [int(x) for x in input()]
	x = int(input())
	arr = [1 for _ in st]
	n = len(st)
	for i in range(len(st)):
		if st[i] == 0:
			if i - x >= 0:
				arr[i - x] = 0
			if i + x < len(st):
				arr[i + x] = 0
	for i in range(len(st)):
		if st[i] == 1:
			if i + x < n and arr[i + x] == 1 or (i - x >= 0 and arr[i - x] == 1):
				continue
			else:
				break
	else:
		for i in arr:
			print(i, end='')
		print()
		continue
	print('-1')


import sys
I = lambda : int(input())
RL = readline = lambda : sys.stdin.readline().strip('\n')
RM = readmap = lambda x=int: map(x, readline().split(' '))
for _ in range(I()):
	(s, x) = (RL(), I())
	n = len(s)
	w = ['1'] * n
	for (ind, i) in enumerate(s):
		if i == '0':
			(i1, i2) = (ind - x, ind + x)
			if i1 >= 0:
				w[i1] = '0'
			if i2 < n:
				w[i2] = '0'
	imp = False
	for (ind, i) in enumerate(s):
		(i1, i2) = (ind - x, ind + x)
		flag = i1 >= 0 and w[i1] == '1' or (i2 < n and w[i2] == '1')
		if '01'[flag] != i:
			imp = True
			break
	print(''.join(w) if not imp else -1)


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def Solution(s, n, x):
	res = ['1' for _ in range(n)]
	flag = False
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				res[i - x] = '0'
			if i + x < n:
				res[i + x] = '0'
	constructStr = ['0' for _ in range(n)]
	for i in range(n):
		if i - x >= 0 and res[i - x] == '1':
			constructStr[i] = '1'
		elif i + x < n and res[i + x] == '1':
			constructStr[i] = '1'
		else:
			constructStr[i] = '0'
	for i in range(n):
		if s[i] != constructStr[i]:
			flag = True
			break
	if flag:
		print(-1)
	else:
		print(''.join(res))

def main():
	for _ in range(get_int()):
		s = get_string()
		x = get_int()
		Solution(s, len(s), x)
main()


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if x + i < n:
				ans[i + x] = '0'
			if i >= x:
				ans[i - x] = '0'
	tmp = 0
	for i in range(n):
		if s[i] == '1':
			if x + i < n and ans[i + x] == '1':
				continue
			elif i >= x and ans[i - x] == '1':
				continue
			else:
				tmp = -1
				break
	if tmp == -1:
		print(-1)
	else:
		a = ''
		for i in ans:
			a += i
		print(a)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	s = input()
	n = len(s)
	x = iinput()
	w = ['1' for _ in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	ans = True
	for i in range(n):
		if i >= x and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			if s[i] != '1':
				ans = False
				break
		elif s[i] != '0':
			ans = False
			break
	if ans == True:
		print(''.join(w))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	w = [0] * len(s)
	k = True
	for i in range(len(s)):
		if s[i] == '1':
			h = False
			if i - x >= 0:
				if i - x - x >= 0:
					if s[i - x - x] != '0':
						w[i - x] = 1
						h = True
				else:
					w[i - x] = 1
					h = True
			if i + x < len(s):
				if i + x + x < len(s):
					if s[i + x + x] != '0':
						w[i + x] = 1
						h = True
				else:
					w[i + x] = 1
					h = True
			if h == False:
				print(-1)
				k = False
				break
	w1 = ''
	for i in w:
		w1 += str(i)
	if k == True:
		print(w1)


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
test = int(input().strip())
for t in range(0, test):
	s = [int(x) for x in list(input().strip())]
	ans = [1] * len(s)
	x = int(input().strip())
	for i in range(len(s)):
		if s[i] == 0:
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < len(s):
				ans[i + x] = 0
	flag = False
	for i in range(len(s)):
		if s[i] == 1:
			(a, b) = (0, 0)
			if i - x >= 0 and ans[i - x] == 1:
				a = 1
			if i + x < len(s) and ans[i + x] == 1:
				b = 1
			if a + b == 0:
				flag = True
	if flag:
		print(-1)
	else:
		print(''.join([str(x) for x in ans]))
	ans = solve()


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	for j in range(len(s)):
		if s[j] == '0':
			if j + x < len(s):
				w[j + x] = '0'
			if j - x >= 0:
				w[j - x] = '0'
	c = 0
	for j in range(len(s)):
		if s[j] == '1':
			if j + x < len(s) and w[j + x] == '1':
				continue
			elif j - x >= 0 and w[j - x] == '1':
				continue
			else:
				c = -1
				break
		if s[j] == '0':
			if j + x < len(s):
				if w[j + x] != '0':
					c = -1
					break
			if j - x >= 0:
				if w[j - x] != '0':
					c = -1
					break
	r = ''
	r = r.join(w)
	if c == -1:
		print(c)
	else:
		print(r)


T = int(input())
for _ in range(T):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	f = 1
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
				continue
			else:
				f = 0
				break
	a = ''
	if f:
		print(a.join(ans))
	else:
		print(-1)


for tt in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	ans = [' ' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			for j in [i - x, i + x]:
				if 0 <= j and j < n:
					ans[j] = '0'
	good = True
	for i in range(n):
		if s[i] == '0':
			if ans[i] != '0':
				ans[i] = '1'
			continue
		l = 0 <= i - x and ans[i - x] != '0'
		r = i + x < n and ans[i + x] != '0'
		if not l and (not r):
			good = False
		if l:
			ans[i - x] = '1'
		if r:
			ans[i + x] = '1'
	print(''.join(ans) if good and ' ' not in ans else -1)


def main():
	t = int(input())
	for i in range(t):
		s = input()
		n = len(s)
		x = int(input())
		answer = [1 for i in range(n)]
		for i in range(n):
			if s[i] == '0':
				if i - x >= 0:
					answer[i - x] = 0
				if i + x < n:
					answer[i + x] = 0
		possible = True
		for i in range(n):
			if s[i] == '1':
				if i - x >= 0 and answer[i - x] or (i + x < n and answer[i + x]):
					pass
				else:
					possible = False
					break
		if possible:
			print(*answer, sep='')
		else:
			print(-1)
main()


t = int(input())
for tt in range(t):
	s = input()
	x = int(input())
	l = ['t'] * len(s)
	f = 1
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				if l[i - x] == 't' or l[i - x] == '0':
					l[i - x] = '0'
				else:
					f = 0
					break
			if i + x < len(s):
				l[i + x] = '0'
		if s[i] == '1':
			if i - x >= 0 and (l[i - x] == 't' or l[i - x] == '1'):
				l[i - x] = '1'
				if i + x * 2 >= len(s) and i + x < len(s):
					l[i + x] = '1'
			elif i + x < len(s):
				l[i + x] = '1'
			else:
				f = 0
				break
	if f == 0:
		print(-1)
		continue
	for i in range(len(l)):
		if l[i] == 't':
			l[i] = '1'
	print(''.join(l))


def solve(s, x, n):
	arr = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				arr[i - x] = 0
			if i + x < n:
				arr[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x < 0 and i + x >= n:
				return -1
			if i - x < 0:
				if i + x < n:
					if arr[i + x] == 0:
						return -1
			if i + x >= n:
				if i - x >= 0:
					if arr[i - x] == 0:
						return -1
			if i - x >= 0 and i + x < n:
				if arr[i - x] == 0 and arr[i + x] == 0:
					return -1
	return ''.join(map(str, arr))
t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	print(solve(s, x, len(s)))


for _ in range(int(input())):
	s = input()
	x = int(input())
	result = ['1' for _ in range(len(s))]
	for (i, c) in enumerate(s):
		if c == '0':
			if i + x < len(s):
				result[i + x] = '0'
			if i - x >= 0:
				result[i - x] = '0'
	possible = True
	for (i, c) in enumerate(s):
		if c == '1':
			(bit1, bit2) = ('0', '0')
			if i + x < len(s):
				bit1 = result[i + x]
			if i - x >= 0:
				bit2 = result[i - x]
			if bit1 == '0' and bit2 == '0':
				possible = False
				break
	print(''.join(result) if possible else '-1')


T = int(input())
output = ['0'] * T
for t in range(T):
	s = input()
	n = len(s)
	x = int(input())
	w = ['1'] * n
	s_new = ['0'] * n
	for (i, si) in enumerate(s):
		if si == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if i >= x and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			s_new[i] = '1'
	output[t] = ''.join(w) if s == ''.join(s_new) else '-1'
print('\n'.join(output))


t = int(input())
for _ in range(t):
	s = list(input())
	x = int(input())
	l = len(s)
	news = ['-1'] * l
	flag = 1
	for i in range(l):
		if s[i] == '1':
			if i - x >= 0 and abs(int(news[i - x])) == 1:
				news[i - x] = '1'
				continue
			elif i + x < l and abs(int(news[i + x])) == 1:
				news[i + x] = '1'
				continue
			else:
				print(-1)
				flag = 0
				break
		else:
			if i - x >= 0:
				if news[i - x] != '0' and news[i - x] != '-1':
					print(-1)
					flag = 0
					break
				else:
					news[i - x] = '0'
			if i + x < l:
				if news[i + x] != '0' and news[i + x] != '-1':
					print(-1)
					flag = 0
					break
				else:
					news[i + x] = '0'
			elif i - x < 0:
				news[i] = '0'
	if flag:
		for i in range(len(news)):
			if news[i] == '-1':
				news[i] = '1'
		print(''.join(news))


t = int(input())
for j in range(t):
	s = input()
	x = int(input())
	n = len(s)
	w = [1 for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i + x <= n - 1:
				w[i + x] = 0
			if i >= x:
				w[i - x] = 0
	d = 0
	for i in range(n):
		if s[i] == '1':
			if not (i + x <= n - 1 and w[i + x] == 1 or (i >= x and w[i - x] == 1)):
				d = -1
				break
	if d == -1:
		print(-1, end='')
	else:
		for i in range(n):
			print(w[i], end='')
	print()


from sys import stdin
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip()
	n = len(s)
	x = int(stdin.readline())
	res = ['1'] * n
	for (i, c) in enumerate(s):
		if c == '0':
			if i + x < n:
				res[i + x] = '0'
			if i - x > -1:
				res[i - x] = '0'
	for i in range(n):
		one = False
		one = one or (i - x >= 0 and res[i - x] == '1')
		one = one or (i + x < n and res[i + x] == '1')
		cur = '1' if one else '0'
		if s[i] != cur:
			res = ['-1']
			break
	print(''.join(res))


for _ in range(int(input())):
	s = input()
	x = int(input())
	ans = ['1'] * len(s)
	fc = ['x'] * len(s)
	flag = 0
	n = len(s)
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		if i - x >= 0 and ans[i - x] == '1':
			fc[i] = '1'
		elif i + x < n and ans[i + x] == '1':
			fc[i] = '1'
		else:
			fc[i] = '0'
	fc = ''.join(fc)
	if fc == s:
		ans = ''.join(ans)
		print(ans)
	else:
		print(-1)


t = int(input())
for tt in range(0, t):
	sti = input()
	s = list(sti)
	n = len(s)
	x = int(input())
	ans = ['0'] * n
	for i in range(0, n):
		j = i - x
		fut = i + x
		if j >= 0 and fut < n:
			if s[j] == '1' and s[fut] == '1':
				ans[i] = '1'
		elif j >= 0:
			if s[j] == '1':
				ans[i] = '1'
		elif fut < n:
			if s[fut] == '1':
				ans[i] = '1'
	list2 = ['0'] * n
	for i in range(0, n):
		if ans[i] == '1':
			j = i - x
			fut = i + x
			if j >= 0:
				list2[j] = '1'
			if fut < n:
				list2[fut] = '1'
	if s == list2:
		print(''.join(ans))
	else:
		print(-1)


for i in range(int(input())):
	s = list(str(input()))
	x = int(input())
	ss = '1' * len(s)
	s = list(s)
	ss = list(ss)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0 and i - x < len(s):
				ss[i - x] = '0'
			if i + x <= len(s) - 1 and i + x >= 0:
				ss[i + x] = '0'
	wo = True
	for i in range(len(ss)):
		if s[i] == '1':
			if i - x >= 0 and i - x < len(s) and (ss[i - x] == '1'):
				continue
			if i + x < len(s) and i + x >= 0 and (ss[i + x] == '1'):
				continue
			wo = False
	if wo:
		an = ''.join(ss)
		print(an)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	s = input()
	x = int(input())
	n = len(s)
	res = ['1'] * n
	temp = ''
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				res[i - x] = '0'
			if i + x < n:
				res[i + x] = '0'
	for i in range(n):
		curr = '0'
		if i - x >= 0 and res[i - x] == '1':
			curr = '1'
		if i + x < n and res[i + x] == '1':
			curr = '1'
		temp += curr
	if temp != s:
		print(-1)
		continue
	print(''.join(res))


from sys import *
input = stdin.readline
for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s) - 1
	w = ['-1'] * n
	for i in range(n):
		if s[i] == '0':
			if 0 <= i + x < n:
				w[i + x] = '0'
			if 0 <= i - x < n:
				w[i - x] = '0'
	flag = 1
	for i in range(n):
		if s[i] == '1':
			c = 0
			if 0 <= i + x < n and w[i + x] == '-1':
				c += 1
				w[i + x] = '1'
			if 0 <= i - x < n and (w[i - x] == '-1' or w[i - x] == '1'):
				c += 1
				w[i - x] = '1'
			if c == 0:
				flag = 0
	if flag == 0:
		stdout.write('-1\n')
	else:
		for i in range(n):
			if w[i] == '-1':
				w[i] = '0'
		s = ''.join(w)
		stdout.write(s + '\n')


def run(s, x):
	n = len(s)
	ans = ['2' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			flag = False
			if i - x >= 0:
				if ans[i - x] != '0':
					flag = True
			if i + x < n:
				if ans[i + x] != '0':
					flag = True
			if not flag:
				return ['-1']
	for i in range(n):
		if ans[i] == '2':
			ans[i] = '1'
	return ans
for _ in range(int(input())):
	s = input()
	x = int(input())
	[print(i, end='') for i in run(s, x)]
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	l = list(input())
	x = int(input())
	l = l[:-1]
	res = []
	n = len(l)
	ans1 = ['1'] * n
	for i in range(n):
		if l[i] == '0':
			if i + x < n:
				ans1[i + x] = '0'
			if i - x >= 0:
				ans1[i - x] = '0'
	flag = 1
	cnt = 0
	for i in range(n):
		if l[i] == '1':
			cnt = 0
			if i + x < n and ans1[i + x] == '1':
				cnt += 1
			if i - x >= 0 and ans1[i - x] == '1':
				cnt += 1
			if cnt == 0:
				flag = 0
				break
	if flag == 0:
		print(-1)
	else:
		print(''.join(ans1))


T = int(input())
for t in range(T):
	s = input()
	n = len(s)
	x = int(input())
	w = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				w[i + x] = 0
			if i - x >= 0:
				w[i - x] = 0
	for i in range(n):
		expected = 0
		if i - x >= 0:
			expected += w[i - x]
		if i + x < n:
			expected += w[i + x]
		if expected >= 1:
			expected = 1
		if int(s[i]) != expected:
			print(-1)
			break
	else:
		print(''.join([str(i) for i in w]))


tc = int(input())
for t in range(tc):
	s = input()
	x = int(input())
	n = len(s)
	w = [-1 for _ in range(len(s))]
	later = []
	pos = True
	for i in range(len(s)):
		if i + x >= n and i - x < 0:
			if s[i] == '1':
				pos = False
				print(-1)
				break
			else:
				continue
		elif i + x >= n and i - x >= 0:
			if w[i - x] == -1:
				w[i - x] = s[i]
			elif w[i - x] != s[i]:
				pos = False
				print(-1)
				break
			else:
				continue
		elif i + x < n and i - x < 0:
			if w[i + x] == -1:
				w[i + x] = s[i]
			elif w[i + x] != s[i]:
				pos = False
				print(-1)
				break
			else:
				continue
		elif s[i] == '0':
			if w[i + x] == '1' or w[i - x] == '1':
				pos = False
				print(-1)
				break
			else:
				w[i + x] = '0'
				w[i - x] = '0'
		else:
			later.append(i)
	if pos:
		for idx in later:
			if w[idx + x] == '0' and w[idx - x] == '0':
				pos = False
				print(-1)
				break
			else:
				if w[idx + x] == -1:
					w[idx + x] = '1'
				if w[idx - x] == -1:
					w[idx - x] = '1'
	if pos:
		for i in range(len(w)):
			if w[i] == -1:
				w[i] = '0'
		print(''.join(w))


def stringi(L):
	r = ''
	for l in L:
		r += str(l)
	return r

def construct(w, x):
	n = len(w)
	S = [0] * n
	for i in range(n):
		if i >= x:
			if w[i - x] == '1':
				S[i] = '1'
		if i + x < n:
			if w[i + x] == '1':
				S[i] = '1'
	S = stringi(S)
	return S
T = int(input())
for i in range(T):
	s = input()
	x = int(input())
	n = len(s)
	w = [0] * n
	for i in range(n):
		if i >= x and i + x < n:
			if s[i - x] == s[i + x] == '1':
				w[i] = '1'
		elif i >= x:
			if s[i - x] == '1':
				w[i] = '1'
		elif i + x < n:
			if s[i + x] == '1':
				w[i] = '1'
	w = stringi(w)
	S = construct(w, x)
	if S != s:
		print(-1)
	else:
		print(w)


for _ in range(int(input())):
	s = list(map(int, list(input())))
	n = len(s)
	x = int(input())
	res = [1] * n
	for i in range(n):
		if s[i] == 0:
			if i + x < n:
				res[i + x] = 0
			if i - x >= 0:
				res[i - x] = 0
	bad = False
	for i in range(n):
		acc = 0
		if i + x < n:
			acc += res[i + x]
		if i - x >= 0:
			acc += res[i - x]
		if s[i] == 1 and acc == 0:
			bad = True
			break
	if bad:
		print(-1)
	else:
		print(''.join(map(str, res)))


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	s = inp()
	x = int(inp())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x > -1:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if not (i - x > -1 and w[i - x] == '1' or (i + x < len(s) and w[i + x] == '1')):
				print(-1)
				break
	else:
		print(''.join(map(str, w)))


def reconstruct(s, x):
	w = '1' * len(s)
	m = list(w)
	l = []
	for i in range(len(s)):
		if s[i] == '0':
			if i + 1 + x <= len(s):
				m[i + x] = '0'
			if i + 1 > x:
				m[i - x] = '0'
	for i in range(len(s)):
		flag = 0
		if s[i] == '1':
			if i + 1 > x:
				if m[i - x] == '1':
					flag = 1
					l.append(i - x)
			if i + 1 + x <= len(s):
				if m[i + x] == '1':
					flag = 1
					l.append(i + x)
			if flag == 0:
				return -1
	ans = ''.join(m)
	return ans
t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	print(reconstruct(s, x))


t = int(input())
while t:
	t -= 1
	s = input()
	x = int(input())
	n = len(s)
	l = [-1] * n
	d = set()
	for i in range(n):
		if s[i] == '0':
			d.add(i)
	for i in d:
		if i - x > -1:
			l[i - x] = 0
		if i + x < n:
			l[i + x] = 0
	ans = True
	for i in range(n):
		if i not in d:
			if i - x > -1:
				if l[i - x] != 0:
					l[i - x] = 1
					continue
			if i + x < n:
				if l[i + x] != 0:
					l[i + x] = 1
					continue
			ans = False
			break
	if not ans:
		print(-1)
	else:
		ans = ''
		for i in l:
			if i == -1:
				ans += '1'
			else:
				ans += str(i)
		print(ans)


for t in range(int(input())):
	s = input()
	x = int(input())
	l = ['1'] * len(s)
	flag = 0
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				l[i + x] = '0'
			if i - x >= 0:
				l[i - x] = '0'
	l1 = []
	a = ''
	for i in range(len(l)):
		if i + x < len(l) and l[i + x] == '1' or (i - x >= 0 and l[i - x] == '1'):
			l1.append('1')
		else:
			l1.append('0')
	a = ''.join(l1)
	if a != s:
		print(-1)
		continue
	for i in range(len(l)):
		if i == len(s) - 1:
			print(l[i])
		else:
			print(l[i], end='')


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	w = ['1' for x in range(n)]
	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'
	f = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
				pass
			else:
				f = 1
	if f == 1:
		print(-1)
	else:
		print(''.join(w))


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	s = inp()
	n = len(s)
	x = int(inp())
	w = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i + 1 > x:
				w[i - x] = 0
			if i + x <= n - 1:
				w[i + x] = 0
	for i in range(n):
		f1 = True
		f2 = True
		if s[i] == '1':
			if i + 1 > x:
				if w[i - x] != 0:
					f1 = False
			if i + x <= n - 1:
				if w[i + x] != 0:
					f2 = False
			if f1 and f2:
				print(-1)
				break
	else:
		print(''.join(map(str, w)))


import datetime
t = int(input())
for _ in range(t):
	string = input()
	x = int(input())
	original_string = ['1'] * len(string)
	for i in range(len(string)):
		if string[i] == '0':
			if i - x >= 0:
				original_string[i - x] = '0'
			if i + x < len(string):
				original_string[i + x] = '0'
	for i in range(len(string)):
		if string[i] == '1':
			if i - x >= 0 and original_string[i - x] == '1' or (i + x < len(string) and original_string[i + x] == '1'):
				continue
			else:
				print(-1)
				break
	else:
		print(''.join(original_string))


import sys

def input():
	a = sys.stdin.readline()
	if a[-1] == '\n':
		a = a[:-1]
	return a

def print(*argv):
	n = len(argv)
	for i in range(n):
		if i == n - 1:
			sys.stdout.write(str(argv[i]) + '\n')
		else:
			sys.stdout.write(str(argv[i]) + ' ')

def lcm(x, y):
	from math import gcd
	return x * y / gcd(x, y)

def solve(s, x):
	l = len(s)
	w = [1] * l
	for i in range(l):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x <= l - 1:
				w[i + x] = 0
	for i in range(l):
		if s[i] == '1':
			if i - x >= 0 and i + x <= l - 1:
				if w[i - x] + w[i + x] == 0:
					return -1
			elif i - x >= 0 and w[i - x] == 0:
				return -1
			elif i + x <= l - 1 and w[i + x] == 0:
				return -1
			elif i - x < 0 and i + x > l - 1:
				return -1
	return ''.join(list(map(str, w)))
for _ in range(int(input())):
	s = input()
	x = int(input())
	print(solve(s, x))


def slv():
	s = input()
	k = int(input())
	n = len(s)
	pokita = 1
	nes = ['?' for _ in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i + k < n:
				nes[i + k] = '0'
			if i - k >= 0:
				nes[i - k] = '0'
	gok = 1
	for i in range(n):
		if s[i] == '1':
			pok = 0
			if i + k < n and nes[i + k] != '0':
				pok = 1
				nes[i + k] = '1'
			if i - k >= 0 and nes[i - k] != '0':
				pok = 1
				nes[i - k] = '1'
			if not pok:
				gok = 0
	for i in range(n):
		if nes[i] == '?':
			nes[i] = '1'
	if gok == 0:
		print('-1')
	else:
		print(''.join(map(str, nes)))
t = int(input())
for _ in range(t):
	slv()


import sys
for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	d = dict()
	lol = [0] * n
	lol[0] = 1
	for i in range(-x, n + x):
		if i < 0:
			d[i] = 0
			lol[0] = 1
		elif i >= n:
			d[i] = 0
			lol[0] = 1
		else:
			d[i] = 1
			lol[0] = 1
	flag = 0
	for i in range(n):
		lol[0] = 1
		if s[i] == '0':
			lol[0] = 1
			d[i + x] = 0
			lol[0] = 1
			d[i - x] = 0
			lol[0] = 1
	for i in range(n):
		lol[0] = 1
		if s[i] == '1':
			lol[0] = 1
			if d[i - x] == 0 and d[i + x] == 0:
				lol[0] = 1
				flag = 1
				lol[0] = 1
				break
			elif d[i - x] == 0:
				lol[0] = 0
				d[i + x] = 1
				lol[0] = 0
			else:
				lol[0] = 0
				d[i - x] = 1
	ans = []
	lol[0] = 0
	for i in range(n):
		lol[0] = 0
		ans.append(str(d[i]))
		lol[0] = 0
	lol.sort()
	print(''.join(ans) if flag == 0 else '-1')


import sys
lines = sys.stdin.read().splitlines()
lincnt = -1

def input():
	global lincnt
	lincnt += 1
	return lines[lincnt]
for _ in range(int(input())):
	s = input()
	x = int(input())
	r = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i >= x:
				r[i - x] = '0'
			if i <= len(s) - 1 - x:
				r[i + x] = '0'
	t = []
	for i in range(len(s)):
		if i >= x and r[i - x] == '1':
			t.append('1')
		elif i <= len(s) - 1 - x and r[i + x] == '1':
			t.append('1')
		else:
			t.append('0')
	if s == ''.join(t):
		print(''.join(r))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	dp = [-1] * n
	flag = 0
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				dp[i - x] = 0
			if i + x < n:
				dp[i + x] = 0

	def check(arr):
		for i in range(n):
			if s[i] == '1':
				if not (i - x >= 0 and arr[i - x] != 0 or (i + x < n and arr[i + x] != 0)):
					return False
		return True
	if not check(dp):
		print(-1)
	else:
		for i in dp:
			if i == 0:
				print('0', end='')
			else:
				print('1', end='')
		print()


t = int(input())
for _ in range(t):
	s = list(input())
	x = int(input())
	n = len(s)
	a = ['1'] * n
	tr = 1
	for i in range(n):
		if s[i] == '0':
			if i + x < n and i - x >= 0:
				a[i + x] = '0'
				a[i - x] = '0'
			elif i + x < n:
				a[i + x] = '0'
			elif i - x >= 0:
				a[i - x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i + x < n and a[i + x] == '1' or (i - x >= 0 and a[i - x] == '1'):
				continue
			else:
				tr = 0
				break
	if tr == 0:
		print('-1')
	else:
		print(''.join(a))


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	s = input().split()[0]
	n = len(s)
	x = int(input())
	l = [-1] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				l[i - x] = '0'
			if i + x < n:
				l[i + x] = '0'
	for i in range(n):
		if l[i] == -1:
			l[i] = '1'
	ss = ''
	for i in range(n):
		if i + x < n and i - x >= 0:
			if l[i + x] == '1' or l[i - x] == '1':
				ss += '1'
			else:
				ss += '0'
		elif i + x < n:
			if l[i + x] == '1':
				ss += '1'
			else:
				ss += '0'
		elif i - x >= 0:
			if l[i - x] == '1':
				ss += '1'
			else:
				ss += '0'
		else:
			ss += '0'
	if ss == s:
		print(''.join(l))
	else:
		print(-1)
	t -= 1


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def btod(n):
	return int(n, 2)

def dtob(n):
	return bin(n).replace('0b', '')

def solution():
	for _ in range(Int()):
		a = Str()
		x = Int()
		w = ['1'] * len(a)
		mukul = ['0'] * len(a)
		for i in range(len(a)):
			if a[i] == '0':
				if i >= x:
					w[i - x] = '0'
				if i + x < len(a):
					w[i + x] = '0'
		for i in range(len(a)):
			if i >= x:
				if w[i - x] == '1':
					mukul[i] = '1'
			if i + x < len(a):
				if w[i + x] == '1':
					mukul[i] = '1'
		varshney = ''.join(mukul)
		if varshney == a:
			print(''.join(w))
		else:
			print(-1)
solution()


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	l = len(s)
	val = ['1' for j in range(l)]
	for j in range(l):
		if s[j] == '0':
			if j - x >= 0:
				val[j - x] = '0'
			if j + x < l:
				val[j + x] = '0'
	f = 0
	for j in range(l):
		if s[j] == '1':
			if j - x >= 0:
				f += int(val[j - x])
			if j + x < l:
				f += int(val[j + x])
			if f == 0:
				f = 1
				break
			else:
				f = 0
	if f == 0:
		print(''.join(val))
	else:
		print('-1')


def solve():
	s = list(map(int, input()))
	x = int(input())
	n = len(s)
	ans = [1] * n
	for (i, c) in enumerate(s):
		if c == 0:
			if not i - x < 0:
				ans[i - x] = 0
			if not i + x >= n:
				ans[i + x] = 0
	t = [int(not i - x < 0 and ans[i - x] or (not i + x >= n and ans[i + x])) for i in range(n)]
	if t != s:
		return -1
	return ''.join(map(str, ans))
t = int(input())
for _ in range(t):
	print(solve())


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	s = list(sys.stdin.readline().rstrip())
	x = int(sys.stdin.readline())
	n = len(s)
	s = ['-1'] + s
	w = ['-1'] + ['1'] * n
	temp = ['-1'] + ['0'] * n
	match = True
	for i in range(1, n + 1):
		if s[i] == '0':
			if i > x:
				w[i - x] = '0'
			if i + x <= n:
				w[i + x] = '0'
	for i in range(1, n + 1):
		if i > x and w[i - x] == '1':
			temp[i] = '1'
		if i + x <= n and w[i + x] == '1':
			temp[i] = '1'
	for i in range(1, n + 1):
		if temp[i] != s[i]:
			match = False
			break
	if match:
		print(''.join(w[1:]))
	else:
		print(-1)


def findStr(s, x, c):
	enc = list(['0' if c == '1' else '1'] * len(s))
	for i in range(len(s)):
		if s[i] == c:
			if i - x >= 0:
				enc[i - x] = c
			if i + x < len(s):
				enc[i + x] = c
	return enc
for _ in range(int(input())):
	s = list(input())
	x = int(input())
	orig = findStr(s, x, '0')
	enc = findStr(orig, x, '1')
	if enc == s:
		print(''.join(orig))
	else:
		print(-1)


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())

def inp():
	return int(input())

def st1():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	s = st1()
	x = inp()
	n = len(s)
	r = [1 for i in range(n)]
	fl = 0
	for i in range(n):
		if i - x < 0 and i + x > n - 1 and (s[i] == '1'):
			fl = 1
			break
		if s[i] == '0':
			if i - x >= 0:
				r[i - x] = 0
			if i + x <= n - 1:
				r[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			loc = 0
			if i - x >= 0:
				if r[i - x] == 1:
					loc += 1
			if i + x <= n - 1:
				if r[i + x] == 1:
					loc += 1
			if loc == 0:
				fl = 1
				break
	if fl:
		print(-1)
	else:
		for i in r:
			print(i, end='')
		print()


def tc():
	s = input()
	x = int(input())
	n = len(s)
	w = [1] * len(s)
	for (i, ch) in enumerate(s):
		if ch == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	for (i, ch) in enumerate(s):
		if ch == '1':
			(l, r) = (False, False)
			if i - x >= 0 and w[i - x] == 1:
				l = True
			if i + x < n and w[i + x] == 1:
				r = True
			if not (l or r):
				print(-1)
				return
	print(''.join(map(str, w)))
T = int(input())
for _ in range(T):
	tc()


T = int(input())
for t in range(T):
	s = input()
	x = int(input())
	n = len(s)
	ans = [1 for i in range(n)]
	for (i, a) in enumerate(s):
		if a == '1':
			continue
		if i - x >= 0:
			ans[i - x] = 0
		if i + x < n:
			ans[i + x] = 0
	impossible = False
	for (i, a) in enumerate(s):
		if a == '0':
			continue
		if i - x >= 0 and ans[i - x] == 1:
			continue
		if i + x < n and ans[i + x] == 1:
			continue
		impossible = True
		break
	if impossible:
		print('-1')
		continue
	print(''.join((str(x) for x in ans)))


def solve():
	s = input()
	n = len(s)
	x = int(input())
	w = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i < n - x:
				w[i + x] = '0'
	for i in range(n):
		if i >= x and w[i - x] == '1' or (i < n - x and w[i + x] == '1'):
			if s[i] == '0':
				print(-1)
				return
		elif s[i] == '1':
			print(-1)
			return
	print(''.join(w))
t = int(input())
for _ in range(t):
	solve()


def parse(w, x):
	s = []
	for i in range(len(w)):
		b = 0
		if i >= x and w[i - x] == 1:
			b = 1
		if i < len(w) - x and w[i + x] == 1:
			b = 1
		s.append(b)
	return s

def u(r, i, v):
	if r[i] not in (-1, v):
		raise ArithmeticError
	r[i] = v
for _ in range(int(input())):
	(s, x) = (list(map(int, input())), int(input()))
	n = len(s)
	r = [-1] * n
	try:
		for i in range(n):
			if s[i] < 1:
				if i >= x:
					u(r, i - x, 0)
				if i + x < n:
					u(r, i + x, 0)
		for i in range(x):
			if i + x < n:
				u(r, i + x, s[i])
			if n - i - 1 - x >= 0:
				u(r, -i - 1 - x, s[-i - 1])
		for i in range(x, n - x):
			if s[i] < 1:
				continue
			if r[i - x] == 0:
				u(r, i + x, 1)
			elif r[i + x] == 0:
				u(r, i - x, 1)
			else:
				(u(r, i - x, 1), u(r, i + x, 1))
		for i in range(n):
			r[i] = max(0, r[i])
		if parse(r, x) != s:
			print(-1)
		else:
			print(''.join(map(str, r)))
	except ArithmeticError:
		print(-1)


t = int(input())
for _ in range(t):
	flag = True
	w = str(input())
	x = int(input())
	s = [-1] * len(w)
	for (i, ch) in enumerate(w):
		if ch == '0':
			if i - x >= 0:
				s[i - x] = 0
			if i + x < len(w):
				s[i + x] = 0
	for (i, ch) in enumerate(w):
		if ch == '1':
			if i - x < 0 and i + x < len(w):
				if s[i + x] == 0:
					flag = 0
					break
				else:
					s[i + x] = 1
			elif i - x >= 0 and i + x >= len(w):
				if s[i - x] == 0:
					flag = 0
					break
				else:
					s[i - x] = 1
			elif i - x >= 0 and i + x < len(w):
				if s[i - x] == 0 and s[i + x] == 0:
					flag = 0
					break
				elif s[i - x] == 0:
					s[i + x] = 1
				elif s[i + x] == 0:
					s[i - x] = 1
				else:
					s[i + x] = 1
					s[i - x] = 1
	for (i, ch) in enumerate(s):
		if s[i] == -1 and w[i] == '1':
			flag = 0
	if flag == False:
		print(-1)
	else:
		for i in s:
			if i == -1:
				print(0, end='')
			else:
				print(i, end='')
		print(end='\n')


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	flag = False
	arr = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				arr[i + x] = '0'
			if i - x >= 0:
				arr[i - x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i + x < n and i - x < 0:
				if arr[i + x] == '0':
					flag = True
					break
			elif i - x >= 0 and i + x >= n:
				if arr[i - x] == '0':
					flag = True
					break
			elif i + x < n and i - x >= 0:
				if arr[i - x] == '0' and arr[i + x] == '0':
					flag = True
					break
			else:
				flag = True
				break
	if flag:
		print(-1)
		continue
	ans = ''
	for i in arr:
		ans += i
	print(ans)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	s = input()
	x = II()
	li = [-1] * len(s)
	n = len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < n:
				li[i + x] = '0'
			if i - x >= 0:
				li[i - x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i + x < n and li[i + x] == -1:
				continue
			elif i - x >= 0 and li[i - x] == -1:
				continue
			else:
				P(-1)
				return
	for i in range(n):
		if li[i] == -1:
			li[i] = '1'
	print(''.join(li))
	return
t = II()
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	ans = ['1'] * len(s)
	for j in range(len(s)):
		if s[j] == '0':
			if j - x >= 0:
				ans[j - x] = '0'
			if j + x < len(s):
				ans[j + x] = '0'
	for j in range(len(s)):
		if s[j] == '1':
			a = ans[j - x] if j - x >= 0 else -1
			b = ans[j + x] if j + x < len(s) else -1
			if a != '1' and b != '1':
				print('-1')
				break
	else:
		print(''.join(ans))


t = int(input())
answer = []
for _ in range(t):
	string = input()
	x = int(input())
	n = len(string)
	tempo = ['1' for i in range(n)]
	for i in range(n):
		if string[i] == '0':
			if i + x < n:
				tempo[i + x] = '0'
			if i - x >= 0:
				tempo[i - x] = '0'
	for i in range(n):
		if string[i] == '1':
			bool = False
			if i + x < n:
				bool = bool or tempo[i + x] != '0'
			if i - x >= 0:
				bool = bool or tempo[i - x] != '0'
			if not bool:
				tempo = '-1'
				break
	if tempo != '-1':
		tempo = ''.join(tempo)
	answer.append(tempo)
print('\n'.join(answer))


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	ans = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	f = True
	for i in range(n):
		if s[i] == '1':
			f = False
			if i >= x and ans[i - x] != 0:
				f = True
			if i + x < n and ans[i + x] != 0:
				f = True
			if not f:
				break
	if not f:
		print(-1)
	else:
		for i in range(n):
			ans[i] = '1' if ans[i] != 0 else '0'
		print(''.join(ans))


import sys
input = sys.stdin.readline

def const(S):
	n = len(S)
	ANS = ['0'] * n
	for i in range(n):
		if i - x >= 0 and S[i - x] == '1':
			ANS[i] = '1'
		if i + x < n and S[i + x] == '1':
			ANS[i] = '1'
	return ''.join(ANS)
t = int(input())
for tests in range(t):
	S = input().strip()
	x = int(input())
	n = len(S)
	ANS = ['1'] * n
	for i in range(n):
		if S[i] == '0':
			if i - x >= 0:
				ANS[i - x] = '0'
			if i + x < n:
				ANS[i + x] = '0'
	A = ''.join(ANS)
	if const(A) == S:
		print(A)
	else:
		print(-1)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

def check(a, b, x):
	cur = []
	for i in range(len(a)):
		if i >= x and a[i - x] == '1':
			cur.append('1')
		elif i + x < len(a) and a[i + x] == '1':
			cur.append('1')
		else:
			cur.append('0')
	cur = ''.join(cur)
	if cur == b:
		return True
	return False
tc = ii1()
for _ in range(tc):
	s = is1()
	x = ii1()
	res = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i >= x:
				res[i - x] = '0'
			if i + x < len(s):
				res[i + x] = '0'
	if check(res, s, x):
		print(''.join(res))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	bad = False
	ans = ''
	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'
	for i in range(n):
		one = True
		second = True
		if i - x >= 0:
			if w[i - x] == '1':
				one = True
			else:
				one = False
		else:
			one = False
		if i + x < n:
			if w[i + x] == '1':
				second = True
			else:
				second = False
		else:
			second = False
		if one or second:
			if s[i] != '1':
				print(-1)
				bad = True
				break
		if one is False and second is False:
			if s[i] != '0':
				print(-1)
				bad = True
				break
	if not bad:
		for ch in w:
			ans += ch
		print(ans)


from sys import stdin
for _ in range(int(input())):
	s = list(stdin.readline().rstrip())
	x = int(input())
	n = len(s)
	w = ['1'] * n
	test = ['0'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x <= n - 1:
				w[i + x] = '0'
	for i in range(n):
		if i >= x and w[i - x] == '1':
			test[i] = '1'
		if i < n - x and w[i + x] == '1':
			test[i] = '1'
	if test != s:
		print(-1)
	else:
		print(''.join(w))


def solve(string, x):
	n = len(string)
	possible = [{0: True, 1: True} for i in range(n)]
	for i in range(n):
		if string[i] == '0':
			if i >= x:
				possible[i - x][1] = False
			if i + x < n:
				possible[i + x][1] = False
		elif i < x and i + x >= n:
			return -1
		elif i < x:
			possible[i + x][0] = False
		elif i + x >= n:
			possible[i - x][0] = False
		elif not possible[i - x][1] and (not possible[i + x][1]):
			return -1
		elif not possible[i - x][1]:
			possible[i + x][0] = False
		elif not possible[i + x][1]:
			possible[i - x][0] = False
	output = ''
	for p in possible:
		if not p[0] and (not p[1]):
			return -1
		elif not p[0]:
			output += '1'
		elif not p[1]:
			output += '0'
		else:
			output += '1'
	return output

def main():
	t = int(input())
	for _ in range(t):
		string = input()
		x = int(input())
		answer = solve(string, x)
		print(answer)
main()


import sys
INP = lambda : sys.stdin.readline().strip()
INT = lambda : int(INP())
MAP = lambda : map(int, INP().split())
ARR = lambda : [int(i) for i in INP().split()]

def JOIN(arr, x=' '):
	return x.join([str(i) for i in arr])

def EXIT(x='NO'):
	print(x)
	exit()

def good(s2, s, n, x):
	new = [0] * n
	for i in range(n):
		if i - x >= 0 and s2[i - x] or (i + x < n and s2[i + x]):
			new[i] = 1
	return new == s
for _ in range(INT()):
	s = [int(i) for i in list(INP())]
	n = len(s)
	s2 = [1] * n
	x = INT()
	for i in range(n):
		if s[i] == 0:
			if i - x >= 0:
				s2[i - x] = 0
			if i + x < n:
				s2[i + x] = 0
	if good(s2, s, n, x):
		print(JOIN(s2, ''))
	else:
		print(-1)


def controller(s, x):
	n = len(s)
	w = list('1' * n)
	a = -x
	b = x
	for si in s:
		if a >= 0 and si == '0':
			w[a] = '0'
		if b < n and si == '0':
			w[b] = '0'
		if a < 0 and b >= n and (si == '1'):
			return '-1'
		a += 1
		b += 1
	a = -x
	b = x
	for si in s:
		if si == '1':
			if a < 0:
				if b < n and w[b] == '0':
					return '-1'
			elif b < n:
				if w[a] == '0' == w[b]:
					return '-1'
			elif w[a] == '0':
				return '-1'
		a += 1
		b += 1
	return ''.join(w)

def c_in():
	n_test_case = int(input())
	for i in range(n_test_case):
		s = input().rstrip()
		x = int(input())
		print(controller(s, x))
c_in()


import sys
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.141592653589793

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return map(int, sys.stdin.readline().strip().split())

def read_ints2(x):
	return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())

def read_str_list():
	return list(sys.stdin.readline().strip().split())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def GCD(a: int, b: int) -> int:
	return b if a % b == 0 else GCD(b, a % b)

def LCM(a: int, b: int) -> int:
	return a * b // GCD(a, b)

def Main():
	for _ in range(read_int()):
		s = list(read_str())
		x = read_int()
		n = len(s)
		ans = [1] * n
		for (i, ss) in enumerate(s):
			if ss == '0':
				if 0 <= i - x:
					ans[i - x] = 0
				if x + i < n:
					ans[x + i] = 0
		for (i, ss) in enumerate(s):
			if ss == '1':
				flag = True
				if i - x >= 0 and ans[i - x] == 1:
					flag = False
				if i + x < n and ans[i + x] == 1:
					flag = False
				if flag:
					print(-1)
					break
		else:
			print(''.join(map(str, ans)))
Main()


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	s = input()
	n = len(s)
	x = int(input())
	w = [''] * n
	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'
	for i in range(n):
		if w[i] == '':
			w[i] = '1'
	temp = [''] * n
	for i in range(n):
		ok = True
		if i - x >= 0:
			if w[i - x] == '1':
				temp[i] = '1'
				ok = False
		if i + x < len(s):
			if w[i + x] == '1':
				temp[i] = '1'
				ok = False
		if ok:
			temp[i] = '0'
	if ''.join(temp) == s:
		print(''.join(w))
	else:
		print(-1)


import io
import os
from collections import Counter, defaultdict, deque

def WToS(W, X):
	N = len(W)
	S = [0 for i in range(N)]
	for i in range(N):
		S[i] = '0'
		if i - X >= 0 and W[i - X] == '1':
			S[i] = '1'
		if i + X < N and W[i + X] == '1':
			S[i] = '1'
	return ''.join(map(str, S))

def solve(S, X):
	N = len(S)
	W = ['1' for i in range(N)]
	for (i, x) in enumerate(S):
		if x == '0':
			if i + X < N:
				W[i + X] = '0'
			if i - X >= 0:
				W[i - X] = '0'
	W = ''.join(map(str, W))
	if WToS(W, X) == S:
		return W
	return -1
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	S = input().decode().rstrip()
	(X,) = [int(x) for x in input().split()]
	ans = solve(S, X)
	print(ans)


for _ in range(int(input())):
	s = input()
	flag = 0
	x = int(input())
	a = ['-1' for i in range(len(s))]
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and a[i - x] != '0':
				a[i - x] = '1'
			elif i + x < len(s) and a[i + x] != '0':
				a[i + x] = '1'
			else:
				flag = 1
				break
		else:
			if i - x >= 0:
				if a[i - x] != '1':
					a[i - x] = '0'
				else:
					flag = 1
					break
			if i + x < len(s):
				if a[i + x] != '1':
					a[i + x] = '0'
				else:
					break
	for i in range(len(s)):
		if a[i] == '-1':
			a[i] = '1'
	if flag == 0:
		print(''.join(a))
	else:
		print(-1)


t = int(input())
for you in range(t):
	s = input()
	n = len(s)
	x = int(input())
	arr = [1 for i in range(n)]
	poss = 1
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and arr[i - x] == 0 and (i + x < n) and (arr[i + x] == 0):
				poss = 0
				break
		else:
			if i - x >= 0:
				arr[i - x] = 0
			if i + x < n:
				arr[i + x] = 0
	if poss == 0:
		print(-1)
		continue
	isposs = ''
	for i in range(n):
		if i - x >= 0 and arr[i - x]:
			isposs = isposs + '1'
		elif i + x < n and arr[i + x]:
			isposs = isposs + '1'
		else:
			isposs = isposs + '0'
	if isposs == s:
		for i in arr:
			print(i, end='')
		print()
	else:
		print(-1)


def controller(s, x):
	n = len(s)
	w = list('1' * n)
	a = -x
	b = x
	for si in s:
		if si == '0':
			if a >= 0:
				w[a] = '0'
			if b < n:
				w[b] = '0'
		a += 1
		b += 1
	a = -x
	b = x
	for si in s:
		if si == '1':
			if a < 0:
				if b < n:
					if w[b] == '0':
						return '-1'
				else:
					return '-1'
			elif w[a] == '0':
				if b < n:
					if w[b] == '0':
						return '-1'
				else:
					return '-1'
		a += 1
		b += 1
	return ''.join(w)

def c_in():
	n_test_case = int(input())
	for i in range(n_test_case):
		s = input().rstrip()
		x = int(input())
		print(controller(s, x))
from io import StringIO
import sys
sys.stdout = StringIO()
c_in()
print(sys.stdout.getvalue(), file=sys.__stdout__)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	c = 1
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1' or (i + x < len(s) and w[i + x] == '1'):
				continue
			else:
				c = 0
				break
	if c == 1:
		print(''.join(map(str, w)))
	elif c == 0:
		print(-1)


import math
import sys

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def Binary(n):
	if n == 0:
		return '00000000'
	binary = ''
	i = 0
	while n > 0 and i <= 8:
		s1 = str(int(n % 2))
		binary = binary + s1
		n /= 2
		i = i + 1
		d = binary[::-1]
	return d

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())

def knapSack(W, wt, val, n):
	K = [[0 for x in range(W + 1)] for x in range(n + 1)]
	for i in range(n + 1):
		for w in range(W + 1):
			if i == 0 or w == 0:
				K[i][w] = 0
			elif wt[i - 1] <= w:
				K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w])
			else:
				K[i][w] = K[i - 1][w]
	return K[n][W]
for _ in range(int(input())):
	s = input()
	n = int(input())
	ans = ['1'] * len(s)
	f = 0
	for i in range(len(s)):
		if s[i] == '0':
			if i - n >= 0:
				ans[i - n] = '0'
			if i + n < len(s):
				ans[i + n] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if i - n >= 0 and ans[i - n] == '1' or (i + n < len(s) and ans[i + n] == '1'):
				continue
			else:
				f = 1
				break
	if f == 0:
		for i in ans:
			print(i, end='')
		print()
	else:
		print(-1)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	s = SI()
	x = II()
	n = len(s)
	ans = [1] * n
	for (i, c) in enumerate(s):
		if c == '0':
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0

	def ok():
		for i in range(n):
			if s[i] == '1':
				flag = 0
				if i - x >= 0:
					flag |= ans[i - x]
				if i + x < n:
					flag |= ans[i + x]
				if flag == 0:
					return False
		return True
	if ok():
		print(*ans, sep='')
	else:
		print(-1)


def forward(w, x):
	s = [0 for i in w]
	for i in range(len(w)):
		if i - x >= 0 and w[i - x] == 1:
			s[i] = 1
		if i + x < len(w) and w[i + x] == 1:
			s[i] = 1
	return s

def backward(s, x):
	w = [1 for i in s]
	for i in range(len(s)):
		if s[i] == 0:
			if i - x >= 0:
				w[i - x] = 0
			if i + x < len(s):
				w[i + x] = 0
	return w
for t in range(int(input())):
	s = list(map(int, input()))
	n = int(input())
	w = backward(s, n)
	if s != forward(w, n):
		print(-1)
	else:
		print(''.join(map(str, w)))


import sys
input = sys.stdin.buffer.readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
_T_ = inin()
for _t_ in range(_T_):
	s = inst()
	x = inin()
	n = len(s)
	ns = ['1' for i in range(len(s))]
	w = ['1' for i in range(len(s))]
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(len(s)):
		if i - x >= 0 and w[i - x] == '1':
			ns[i] = '1'
		elif i + x < n and w[i + x] == '1':
			ns[i] = '1'
		else:
			ns[i] = '0'
	if ''.join(ns) == s:
		print(''.join(w))
	else:
		print(-1)


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	s = stdin.readline().strip()
	n = int(stdin.readline().strip())
	ans = [1 for i in range(len(s))]
	can = True
	res = ''
	for i in range(len(s)):
		if s[i] == '0':
			if i - n >= 0:
				ans[i - n] = 0
			if i + n < len(s):
				ans[i + n] = 0
	for i in range(len(s)):
		res += str(ans[i])
		t = 0
		if i - n >= 0 and ans[i - n] == 1:
			t = 1
		if i + n < len(s) and ans[i + n] == 1:
			t = 1
		if t != int(s[i]):
			can = False
			break
	if can:
		print(res)
	else:
		print(-1)


def func():
	n = len(s)
	w = ['_'] * n
	for i in range(n):
		if s[i] == '0':
			flag = True
			if i + x < n:
				w[i + x] = '0'
				flag = False
			if i - x > -1:
				w[i - x] = '0'
				flag = False
			if (i - x > -1 or i + x < n) and flag:
				print(-1)
				return
	for i in range(n):
		if s[i] == '1':
			flag = True
			if i + x < n and w[i + x] != '0':
				w[i + x] = '1'
				flag = False
			if i - x > -1 and w[i - x] != '0':
				w[i - x] = '1'
				flag = False
			if flag:
				print(-1)
				return
	for i in range(n):
		if w[i] == '_':
			w[i] = '1'
	print(''.join(w))
for _ in range(int(input())):
	s = list(input())
	x = int(input())
	func()


T = int(input())
for _ in range(T):
	S = input()
	N = int(input())
	L = len(S)
	arr = [0] * L
	iszero = [False] * L
	for i in range(L):
		if S[i] == '0':
			if i - N >= 0:
				iszero[i - N] = True
			if i + N < L:
				iszero[i + N] = True
	used = False
	for i in range(L):
		if S[i] == '1':
			used = False
			if i - N >= 0:
				if not iszero[i - N]:
					used = True
					arr[i - N] = 1
			if i + N < L:
				if not iszero[i + N]:
					used = True
					arr[i + N] = 1
			if not used:
				print(-1)
				break
	else:
		for i in range(L):
			print(arr[i], end='')
		print('')


for _ in range(int(input())):
	w = input()
	x = int(input())
	m = len(w)
	f = 0
	s = set()
	l = ['1'] * m
	for i in range(len(w)):
		if w[i] == '0':
			if i + x < m and i + x > -1:
				s.add(i + x)
			if i - x > -1 and i - x < m:
				s.add(i - x)
	for i in range(len(w)):
		if w[i] == '1':
			if i - x in s and i + x in s or (i + x >= m and i - x < 0) or (i - x in s and i + x >= m) or (i + x in s and i - x < 0):
				f = 1
				break
	if f == 1:
		print(-1)
		continue
	for i in s:
		l[i] = '0'
	print(''.join(l))


def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		s = list(map(int, input()))
		x = iin()
		n = len(s)
		w = [-1] * n
		for i in range(n):
			if not s[i]:
				if i + x < n:
					w[i + x] = 0
				if i - x >= 0:
					w[i - x] = 0
		br = 0
		for i in range(n):
			if s[i]:
				ch = 0
				if i + x < n and w[i + x] == -1:
					ch += 1
				if i - x >= 0 and w[i - x] == -1:
					ch += 1
				if ch:
					pass
				else:
					br = 1
					break
		if br:
			print(-1)
			continue
		w = [i if i != -1 else 1 for i in w]
		print(*w, sep='')
main()


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		s = [int(x) for x in input()]
		x = int(input())
		n = len(s)
		w = [1] * n
		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
		s2 = [-1] * n
		for i in range(n):
			if i - x >= 0 and w[i - x] == 1:
				s2[i] = 1
			elif i + x < n and w[i + x] == 1:
				s2[i] = 1
			else:
				s2[i] = 0
		if s == s2:
			print(*w, sep='')
		else:
			print(-1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().strip()
	n = len(s)
	x = int(input())
	outl = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				outl[i - x] = '0'
			if i + x < n:
				outl[i + x] = '0'
	out = ''.join(outl)
	works = True
	for i in range(n):
		if s[i] == '1':
			if (i < x or out[i - x] == '0') and (i + x >= n or out[i + x] == '0'):
				works = False
				break
	if works:
		print(out)
	else:
		print(-1)


for _ in range(int(input())):
	s = [x for x in input()]
	h = s.copy()
	n = int(input())
	dicti = {}
	come = 0
	for i in range(len(s)):
		if s[i] == '0':
			if i < n and i > len(s) - n - 1:
				continue
			elif i < n:
				h[i + n] = '0'
				if i + n not in dicti:
					dicti[i + n] = 0
			elif i > len(s) - n - 1:
				h[i - n] = '0'
				if i - n not in dicti:
					dicti[i - n] = 0
			else:
				h[i - n] = '0'
				h[i + n] = '0'
				if i + n not in dicti:
					dicti[i + n] = 0
				if i - n not in dicti:
					dicti[i - n] = 0
	for i in range(len(s)):
		if s[i] == '1':
			if i < n and i > len(s) - 1 - n:
				come = 1
				break
			elif i < n:
				if i + n in dicti:
					come = 1
					break
				else:
					h[i + n] = '1'
			elif i > len(s) - 1 - n:
				if i - n in dicti:
					come = 1
					break
				else:
					h[i - n] = '1'
			elif i - n in dicti and i + n in dicti:
				come = 1
				break
			elif i - n in dicti:
				h[i + n] = '1'
			elif i + n in dicti:
				h[i - n] = '1'
			else:
				h[i - n] = '1'
				h[i + n] = '1'
	if come == 1:
		print(-1)
	else:
		hh = ''
		print(hh.join(h))


def answer(A, x):
	dp = [-1] * len(A)
	for i in range(len(A)):
		if i + 1 - x > 0 and i + 1 + x <= len(A):
			if A[i] == '0':
				if dp[i - x] == -1:
					dp[i - x] = '0'
				elif dp[i - x] != A[i]:
					return -1
				if dp[i + x] == -1:
					dp[i + x] = '0'
				elif dp[i + x] != A[i]:
					return -1
			elif dp[i - x] == -1:
				dp[i - x] = '1'
			elif dp[i - x] == '0':
				dp[i + x] = '1'
		elif i + 1 - x > 0:
			if dp[i - x] == -1:
				dp[i - x] = A[i]
			elif dp[i - x] != A[i]:
				return -1
		elif i + 1 + x <= len(A):
			if dp[i + x] == -1:
				dp[i + x] = A[i]
			elif dp[i + x] != A[i]:
				return -1
		elif A[i] == '1':
			return -1
	for i in range(len(A)):
		if dp[i] == -1:
			dp[i] = '1'
	return ''.join(dp)
t = int(input())
for i in range(t):
	s = input()
	n = int(input())
	print(answer(s, n))


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	wArr = [-1 for __ in range(n)]
	ok = True
	for i in range(n):
		if s[i] == '0':
			if i - x > -1:
				wArr[i - x] = 0
			if i + x < n:
				wArr[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			l = i - x
			r = i + x
			if l < 0 and r > n - 1:
				ok = False
				break
			if l >= 0 and r < n:
				if wArr[l] == wArr[r] == 0:
					ok = False
					break
			elif l >= 0:
				if wArr[l] == 0:
					ok = False
					break
			elif r < n:
				if wArr[r] == 0:
					ok = False
					break
			if l >= 0 and wArr[l] == -1:
				wArr[l] = 1
			if r < n and wArr[r] == -1:
				wArr[r] = 1
	for i in range(n):
		if wArr[i] == -1:
			wArr[i] = 1
	if ok == False:
		print(-1)
	else:
		print(''.join([str(x) for x in wArr]))


for _ in range(int(input())):
	s = list(input())
	x = int(input())
	n = len(s)
	m = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				m[i + x] = '0'
			if i - x >= 0:
				m[i - x] = '0'
	res = ['0'] * n
	for i in range(n):
		if i + x < n:
			if m[i + x] == '1':
				res[i] = '1'
				continue
		if i - x >= 0:
			if m[i - x] == '1':
				res[i] = '1'
				continue
	if res == s:
		print(''.join(m))
	else:
		print(-1)


for t in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	st = []
	w = ['1'] * n
	for i in s:
		st.append(i)
	for i in range(n):
		if st[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	flag = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1':
				continue
			if i + x < n and w[i + x] == '1':
				continue
			else:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		print(''.join(w))


def main():
	for _ in range(int(input())):
		s = list(input())
		x = int(input())
		w = ['1'] * len(s)
		for i in range(len(s)):
			if s[i] == '0':
				if i - x > -1:
					w[i - x] = '0'
				if i + x < len(s):
					w[i + x] = '0'
		chk = True
		for i in range(len(s)):
			if s[i] == '1':
				flg = True
				if i - x > -1 and w[i - x] == '1':
					flg = False
				if i + x < len(s) and w[i + x] == '1':
					flg = False
				if flg:
					chk = False
					break
		print(''.join(w) if chk else -1)
main()


def string(arr, x):
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	lst = [1] * len(arr)
	for i in range(len(arr)):
		if arr[i] == 0:
			if i - x >= 0:
				lst[i - x] = 0
			if i + x <= len(arr) - 1:
				lst[i + x] = 0
	if check(arr, lst, x) != -1:
		for i in lst:
			print(i, end='')
		print()
	else:
		print(-1)

def check(arr, lst, x):
	for i in range(len(arr)):
		(k1, k2) = (0, 0)
		if i - x >= 0:
			k1 = lst[i - x]
		if i + x <= len(arr) - 1:
			k2 = lst[i + x]
		if arr[i] != k1 | k2:
			return -1
	return lst
n = int(input())
for i in range(n):
	st = input()
	x = int(input())
	string(list(st), x)


def solve():
	s = list(map(int, input()))
	x = int(input())
	w = [1] * len(s)
	for i in range(len(s)):
		if s[i] == 0:
			if i + x < len(s):
				w[i + x] = 0
			if i - x >= 0:
				w[i - x] = 0
	s_2 = [1] * len(s)
	for i in range(len(s)):
		if i + x < len(s) and i - x >= 0:
			if w[i - x] != 1 and w[i + x] != 1:
				s_2[i] = 0
		elif i + x < len(s) or i - x >= 0:
			if i + x < len(s):
				if w[i + x] != 1:
					s_2[i] = 0
			elif w[i - x] != 1:
				s_2[i] = 0
		else:
			s_2[i] = 0
	if s_2 == s:
		print(''.join(map(str, w)))
	else:
		print(-1)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	s = [int(x) for x in input()]
	x = int(input())
	notPossible = False
	result = [1] * len(s)
	for i in range(len(s)):
		if s[i] == 0:
			if i - x >= 0:
				result[i - x] = 0
			if i + x < len(s):
				result[i + x] = 0
	for i in range(len(s)):
		if s[i] == 1:
			if i - x >= 0 and result[i - x] == 1 or (i + x < len(s) and result[i + x] == 1):
				continue
			else:
				print('-1')
				break
	else:
		result = [str(x) for x in result]
		print(''.join(result))


t = int(input())
for k in range(t):
	(s, x) = (input(), int(input()))
	n = len(s)
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	flag = 0
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
				flag = 0
			else:
				flag = 1
				break
	ans2 = ''
	for i in ans:
		ans2 += i
	if flag == 1:
		print(-1)
	else:
		print(ans2)


t = int(input())
for i in range(0, t):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(0, n):
		if s[i] == '0':
			if i + x < n:
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	check = ''
	for i in range(0, n):
		if i - x >= 0 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
			check += '1'
		else:
			check += '0'
	if check == s:
		print(*ans, sep='')
	else:
		print(-1)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	x = int(input())
	w = ['1' for j in range(n)]
	for j in range(n - x):
		if s[j + x] == '0':
			w[j] = '0'
	f = True
	for j in range(x, n):
		if s[j - x] == '0':
			w[j] = '0'
	for j in range(n):
		if n > j + x:
			if s[j] == '1' and w[j + x] == '0':
				if j - x >= 0 and w[j - x] == '0' or j - x < 0:
					f = False
		elif j - x >= 0:
			if s[j] == '1' and w[j - x] == '0':
				f = False
		elif s[j] == '1':
			f = False
	if f:
		ans = ''
		for j in w:
			ans += j
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	s = str(input())
	x = int(input())
	n = len(s)
	w = [1] * n
	for i in range(n):
		if i - x >= 0 and s[i] == '0':
			w[i - x] = 0
		if i + x < n and s[i] == '0':
			w[i + x] = 0
	f = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == 1 or (i + x < n and w[i + x] == 1):
				continue
			else:
				f = 1
	if f == 1:
		print(-1)
	else:
		for i in range(n):
			print(w[i], end='')
		print()


def stringslicing(string, index):
	if index >= 0 and index < len(string):
		return string[index]
	else:
		return 'not defined'
t = int(input())
for _ in range(t):
	string = input().strip()
	s = int(input())
	answer = {}
	answer = answer.fromkeys(range(0, len(string)), '1')
	for i in range(len(string)):
		if string[i] == '0':
			a = i - s
			b = i + s
			if a >= 0 and a < len(string):
				answer[a] = '0'
			if b >= 0 and b < len(string):
				answer[b] = '0'
	ans = ''.join(answer.values())
	wrong = 0
	for k in range(len(string)):
		if string[k] == '1':
			if string[k] == stringslicing(ans, k + s) or string[k] == stringslicing(ans, k - s):
				continue
			else:
				print(-1)
				wrong = 1
				break
	if wrong == 0:
		print(ans)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	no = False
	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'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
				no = False
			else:
				no = True
				break
	if no:
		print('-1')
	else:
		print(''.join(w))


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	s = list(input())
	x = r()
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if 0 <= i - x < n:
				ans[i - x] = '0'
			if 0 <= i + x < n:
				ans[i + x] = '0'
	ss = ''
	for i in range(n):
		if 0 <= i - x < n:
			if ans[i - x] == '1':
				ss += '1'
				continue
		if 0 <= i + x < n:
			if ans[i + x] == '1':
				ss += '1'
				continue
		ss += '0'
	if ss == ''.join(s):
		print(''.join(ans))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	l = len(s)
	ans = ['1'] * l
	for i in range(l):
		a = i - x >= 0
		b = i + x < l
		if s[i] == '0':
			if a and b:
				ans[i + x] = '0'
				ans[i - x] = '0'
			elif a:
				ans[i - x] = '0'
			elif b:
				ans[i + x] = '0'
	for i in range(l):
		if s[i] == '0':
			if i - x >= 0 and ans[i - x] != '0':
				ans = ['-1']
				break
			if i + x < l and ans[i + x] != '0':
				ans = ['-1']
				break
		else:
			flag = False
			if i - x >= 0 and ans[i - x] != '0':
				flag = True
			if i + x < l and ans[i + x] != '0':
				flag = True
			if flag == False:
				ans = [-1]
				break
	print(*ans, sep='')


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	x = int(input())
	ans = [''] * n
	flag = 0
	for j in range(n):
		if s[j] == '0':
			if j - x >= 0:
				ans[j - x] = 0
			if j + x <= n - 1:
				ans[j + x] = 0
	for j in range(n):
		if s[j] == '1':
			if j - x < 0 and j + x > n - 1:
				flag = 1
				break
			elif j - x >= 0 and j + x <= n - 1:
				if ans[j - x] == 0 and ans[j + x] == 0:
					flag = 1
					break
				else:
					if ans[j - x] != 0:
						ans[j - x] = 1
					if ans[j + x] != 0:
						ans[j + x] = 1
			elif j - x >= 0:
				if ans[j - x] == 0:
					flag = 1
					break
				else:
					ans[j - x] = 1
			elif j + x <= n - 1:
				if ans[j + x] == 0:
					flag = 1
					break
				else:
					ans[j + x] = 1
	if flag == 0:
		for j in range(n):
			if ans[j] == '':
				ans[j] = 1
		ans = [str(cv) for cv in ans]
		print(''.join(ans))
	else:
		print(-1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = list(input().strip())
	n = len(s)
	x = int(input())
	r = [-1] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				r[i - x] = '0'
			if i + x < n:
				r[i + x] = '0'
	for i in range(n):
		if r[i] == -1:
			r[i] = '1'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and r[i - x] == '1' or (i + x < n and r[i + x] == '1'):
				continue
			print(-1)
			break
	else:
		print(''.join(r))


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	x = int(input())
	b = ['1'] * n
	flag = True
	cool = 0
	for i in range(n):
		if s[i] == '0':
			if i + x <= n - 1:
				b[i + x] = '0'
			if i - x >= 0:
				b[i - x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and b[i - x] == '1' or (i + x <= n - 1 and b[i + x] == '1'):
				cool += 1
			else:
				flag = False
				break
	if flag:
		ans = ''
		for ele in b:
			ans += ele
		print(ans)
	else:
		print(-1)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		s = si()
		x = ii()
		n = len(s)
		s = ' ' + s
		ans = [0] * (n + 5)
		flag = 1
		f = [0] * (n + 5)
		for i in range(1, n + 1):
			if s[i] == '0':
				if i + x <= n:
					f[i + x] = 1
				if i - x >= 1:
					f[i - x] = 1
		for i in range(1, n + 1):
			if s[i] == '0':
				if i - x >= 1:
					if ans[i - x] == 1:
						flag = 0
						break
				if i + x <= n:
					if ans[i + x] == 1:
						flag = 0
						break
			else:
				enter = 0
				if i - x >= 1 and i + x <= n:
					if f[i - x] == 1 and f[i + x] == 1:
						flag = 0
						break
					elif f[i - x] == 0 and f[i + x] == 0:
						ans[i - x] = 1
						ans[i + x] = 1
					elif f[i - x] == 0:
						ans[i - x] = 1
					elif f[i + x] == 0:
						ans[i + x] = 1
				elif i - x >= 1:
					if f[i - x] == 1:
						flag = 0
						break
					else:
						ans[i - x] = 1
				elif i + x <= n:
					if f[i + x] == 1:
						flag = 0
						break
					else:
						ans[i + x] = 1
				else:
					flag = 0
					break
		if flag == 0:
			print(-1)
		else:
			for i in range(1, n + 1):
				print(ans[i], end='')
			print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve():
	s = list(map(int, input()))
	n = len(s)
	x = int(input())
	w = [0] * n
	d = [False] * n
	for i in range(n):
		if s[i] == 0:
			if i - x >= 0:
				w[i - x] = 0
				d[i - x] = True
			if i + x < n:
				w[i + x] = 0
				d[i + x] = True
	for i in range(n):
		if not d[i]:
			w[i] = 1
			d[i] = True
	t = [0] * n
	for i in range(n):
		if i - x >= 0 and w[i - x] == 1:
			t[i] = 1
		if i + x < n and w[i + x] == 1:
			t[i] = 1
	if s != t:
		print('-1')
		return
	print(''.join(map(str, w)))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	s = [0] + list(map(int, input().strip()))
	x = int(input())
	n = len(s) - 1
	ans = [1 for _ in range(n + 1)]
	for i in range(1, n + 1):
		if s[i] == 0:
			if i > x:
				ans[i - x] = 0
			if i + x <= n:
				ans[i + x] = 0
	for i in range(1, n + 1):
		bit = False
		bit |= i > x and ans[i - x] == 1
		bit |= i + x <= n and ans[i + x] == 1
		if int(bit) != s[i]:
			print(-1)
			break
	else:
		print(''.join(map(str, ans[1:])))


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = [''] * n
	f = True
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i < n - x:
				w[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			ct = 0
			if i >= x:
				if w[i - x] == '':
					w[i - x] = '1'
				ct += int(w[i - x])
			if i < n - x:
				if w[i + x] == '':
					w[i + x] = '1'
				ct += int(w[i + x])
			if ct == 0:
				f = False
				break
		if w[i] == '':
			w[i] = '1'
	print(''.join(w) if f else -1)


def binaryRecon(s, k):
	r = ['1'] * len(s)
	for i in range(len(s)):
		if i - k >= 0 and s[i] == '0':
			r[i - k] = '0'
		if i + k < len(s) and s[i] == '0':
			r[i + k] = '0'
	flag = checker(r, s, k)
	if flag:
		print(''.join(r))
		return
	print(-1)

def checker(lis, s, x):
	for i in range(len(lis)):
		flag = False
		if i - x >= 0 and lis[i - x] == '1':
			flag = True
		if i + x < len(s) and lis[i + x] == '1':
			flag = True
		if s[i] != str(int(flag)):
			return False
	return True
k = int(input())
for i in range(k):
	s = input()
	k = int(input())
	binaryRecon(s, k)


t = int(input())
for i in range(t):
	s = input()
	n = int(input())
	l = len(s)
	arr = ['1'] * l
	flag = 1
	for i in range(l):
		if s[i] == '0':
			if i - n >= 0:
				arr[i - n] = '0'
			if i + n < l:
				arr[i + n] = '0'
	for i in range(l):
		if s[i] == '1':
			slag = 0
			if i - n >= 0 and arr[i - n] == '1':
				slag = 1
			if i + n < l and arr[i + n] == '1':
				slag = 1
			if slag == 0:
				print(-1)
				flag = 0
				break
	if flag == 1:
		s1 = ''
		for i in range(l):
			s1 = s1 + arr[i]
		print(s1)


t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	n = int(input())
	s1 = []
	s2 = []
	for i in range(len(s)):
		s1.append('1')
		s2.append('1')
	for i in range(len(s)):
		if s[i] == '0':
			if i - n >= 0:
				s1[i - n] = '0'
			if i + n < len(s):
				s1[i + n] = '0'
	for i in range(len(s1)):
		if i + n < len(s) and s1[i + n] == '1' or (i - n >= 0 and s1[i - n] == '1'):
			continue
		else:
			s2[i] = '0'
	if s == s2:
		print(''.join(s1))
	else:
		print(-1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	s = data()
	n = len(s)
	answer = ['1'] * n
	x = int(data())
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				answer[i - x] = '0'
			if i + x < n:
				answer[i + x] = '0'
	result = True
	for i in range(n):
		if s[i] == '1':
			r = False
			if i - x >= 0 and answer[i - x] == '1':
				r = True
			if i + x < n and answer[i + x] == '1':
				r = True
			if not r:
				result = False
				break
	if not result:
		out(-1)
		continue
	out(''.join(answer))


gans = []
for _ in range(int(input())):
	s = list(map(int, list(input())))
	n = len(s)
	x = int(input())
	w = [1] * n
	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
	ok = False
	for i in range(n):
		if s[i] == 1:
			cur = []
			if i - x >= 0:
				cur.append(w[i - x])
			if i + x < n:
				cur.append(w[i + x])
			if 1 not in cur:
				ok = True
				break
	if ok:
		gans.append('-1')
	else:
		gans.append(''.join(map(str, w)))
print('\n'.join(gans))


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	f0 = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				f0[i - x] = 0
			if i + x < n:
				f0[i + x] = 0
	u = 0
	for i in range(n):
		if s[i] == '1':
			if i >= x:
				if f0[i - x] == 0:
					if i + x >= n:
						u = 1
					elif f0[i + x] == 0:
						u = 1
			elif i + x < n:
				if f0[i + x] == 0:
					u = 1
			else:
				u = 1
	f0 = list(map(str, f0))
	if u == 0:
		print(''.join(f0))
	else:
		print(-1)


import sys
from math import sqrt
from collections import defaultdict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def invr():
	return map(int, inpt().split())

class Graph:

	def __init__(self, n):
		self.n = n
		self.graph = defaultdict(list)
		self.marked = defaultdict(int)

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def dfs(self, u):
		self.marked[u] = 1
		for i in self.graph[u]:
			if self.marked[i] == 0:
				self.dfs(i)

def main():
	t = inp()
	for l in range(t):
		s = instr()
		x = inp()
		w = ['1'] * len(s)
		for i in range(len(s)):
			if s[i] == '0':
				if i - x >= 0:
					w[i - x] = '0'
				if i + x < len(s):
					w[i + x] = '0'
		chk = True
		for i in range(len(s)):
			if s[i] == '1':
				if (i - x < 0 or w[i - x] == '0') and (i + x >= len(s) or w[i + x] == '0'):
					chk = False
					break
		if chk:
			for i in range(len(w)):
				print(w[i], end='')
			print()
		else:
			print(-1)
main()


import sys
t = int(input())
i = 0
for line in sys.stdin:
	if i == 0:
		s = line[:-1]
	else:
		x = int(line)
		impossible = False
		w = [-1 for _ in range(len(s))]
		for j in range(len(s)):
			if s[j] == '1':
				if j - x < 0:
					if j + x < len(s):
						w[j + x] = 1
					else:
						impossible = True
						break
				elif j + x >= len(s):
					if j - x >= 0:
						if w[j - x] == 1 or w[j - x] == -1:
							w[j - x] = 1
						else:
							impossible = True
							break
					else:
						impossible = True
						break
				elif w[j - x] == -1 or w[j - x] == 1:
					w[j - x] = 1
				elif w[j + x] == -1 or w[j + x] == 1:
					w[j + x] = 1
				else:
					impossible = True
					break
			else:
				if j - x >= 0:
					if w[j - x] == 1:
						impossible = True
						break
					w[j - x] = 0
				if j + x < len(s):
					if w[j + x] == 1:
						impossible = True
						break
					w[j + x] = 0
		if impossible:
			print(-1)
		else:
			for p in range(len(w)):
				if w[p] == -1:
					w[p] = 1
			print(*w, sep='')
	i = 1 - i


for p in range(int(input())):
	st = input()
	x = int(input())
	n = len(st)
	w = [1] * n
	for i in range(n):
		if st[i] == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	ans = ''
	for i in range(n):
		if i - x >= 0 and w[i - x] == 1 or (i + x < n and w[i + x] == 1):
			ans += '1'
		else:
			ans += '0'
	if ans == st:
		w = list(map(str, w))
		print(''.join(w))
	else:
		print(-1)


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	s = S()
	x = I()
	l = ['1'] * len(s)
	s1 = ''
	for i in range(len(s)):
		if s[i] == '1':
			continue
		if i - x >= 0:
			l[i - x] = '0'
		if i + x < len(s):
			l[i + x] = '0'
	for i in range(len(l)):
		if i - x >= 0 and l[i - x] == '1':
			s1 += '1'
			continue
		if i + x < len(l) and l[i + x] == '1':
			s1 += '1'
			continue
		s1 += '0'
	print(''.join(l) if s == s1 else -1)


import sys
test = int(input())
for i in range(test):
	s = input()
	x = int(input())
	n = len(s)
	w = [0] * n
	for j in range(n):
		if j - x < 0:
			if j + x < n:
				w[j] = int(s[j + x])
		elif j + x >= n:
			if j - x >= 0:
				w[j] = int(s[j - x])
		else:
			w[j] = int(s[j - x]) & int(s[j + x])
	flag = True
	for it in range(n):
		if it - x < 0 and it + x >= n:
			if s[it] == '1':
				flag = False
				break
			continue
		if it - x < 0:
			if int(s[it]) != w[it + x]:
				flag = False
				break
		elif it + x >= n:
			if int(s[it]) != w[it - x]:
				flag = False
				break
		elif int(s[it]) != w[it - x] | w[it + x]:
			flag = False
			break
	if flag == True:
		ans = ''
		for it in range(n):
			ans += str(w[it])
		print(ans)
	else:
		print(-1)


mod = 10 ** 9 + 7

def solve():
	s = input()
	n = len(s)
	x = int(input())
	w = ['?'] * n
	ok = True
	for i in range(n):
		if i + x < n and s[i] == '0':
			w[i + x] = s[i]
		if i - x >= 0 and s[i] == '0':
			w[i - x] = '0'
	for i in range(n):
		if s[i] == '1':
			ok1 = False
			if i + x < n and w[i + x] == '?':
				w[i + x] = '1'
			if i - x >= 0 and w[i - x] == '?':
				w[i - x] = '1'
	for i in range(n):
		if w[i] == '?':
			w[i] = '0'
	for i in range(n):
		c = '0'
		if i + x < n and w[i + x] == '1':
			c = '1'
		if i - x >= 0 and w[i - x] == '1':
			c = '1'
		if c != s[i]:
			ok = False
			break
	print(''.join(w) if ok else -1)
t = int(input())
while t > 0:
	solve()
	t -= 1


def process():
	li = list(input())
	x = int(input())
	n = len(li)
	ans = ['1' for i in range(n)]
	for i in range(0, n):
		if li[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(0, n):
		chr = '0'
		if i - x >= 0 and ans[i - x] == '1':
			chr = '1'
		if i + x < n and ans[i + x] == '1':
			chr = '1'
		if li[i] == chr:
			pass
		else:
			print(-1)
			return
	print(''.join(ans))
tests = int(input())
for i in range(tests):
	process()


def valid(a1):
	if a1 >= 0 and a1 < len(a):
		return True
	return False
for i in range(int(input())):
	a = input()
	b = int(input())
	ans = [-1 for j in a]
	for j in range(len(a)):
		if a[j] == '0':
			if valid(j - b):
				ans[j - b] = 0
			if valid(j + b):
				ans[j + b] = 0
	flag = True
	for j in range(len(a)):
		if a[j] == '1':
			temp1 = 0
			if valid(j - b):
				if ans[j - b] == -1 or ans[j - b] == 1:
					ans[j - b] = 1
					temp1 += 1
			if valid(j + b):
				if ans[j + b] == -1 or ans[j + b] == 1:
					ans[j + b] = 1
					temp1 += 1
			if temp1 == 0:
				flag = False
	if flag:
		res = ''
		for j in ans:
			if j == -1:
				res += str(0)
			else:
				res += str(j)
		print(res)
	else:
		print(-1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	s = list(inp())
	for i in range(len(s)):
		s[i] = int(s[i])
	x = int(inp())
	ans = [1] * len(s)
	n = len(s)
	for i in range(n):
		if s[i] == 0:
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	for i in range(n):
		if s[i] == 1:
			ok = False
			if i - x >= 0:
				if ans[i - x] == 1:
					ok = True
			if i + x < n:
				if ans[i + x] == 1:
					ok = True
			if ok:
				continue
			else:
				print(-1)
				return
	print(''.join((str(ans[i]) for i in range(n))))
testcase(int(inp()))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
T = int(stdin.readline())
for _ in range(T):
	s = str(stdin.readline().strip('\n'))
	x = int(stdin.readline())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	flag = True
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and ans[i - x] == '1':
				continue
				break
			if i + x < n and ans[i + x] == '1':
				continue
			flag = False
	if flag:
		print(''.join(ans))
	else:
		print(-1)


for i in range(int(input())):
	s = input()
	x = int(input())
	l = len(s)
	w = ['1' for j in range(l)]
	for j in range(l):
		if s[j] == '0':
			if j - x >= 0:
				w[j - x] = '0'
			if j + x < l:
				w[j + x] = '0'
	cnt = 0
	for j in range(l):
		if s[j] == '1':
			if j - x >= 0:
				cnt += int(w[j - x])
			if j + x < l:
				cnt += int(w[j + x])
			if cnt == 0:
				cnt = 1
				break
			else:
				cnt = 0
	if cnt == 0:
		print(''.join(w))
	else:
		print('-1')


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	w = [-1] * n
	for (i, c) in enumerate(s):
		if c == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	for i in range(n):
		if w[i] == -1:
			w[i] = 1
	satisfies = True
	for (i, c) in enumerate(s):
		if c == '1':
			if i - x < 0 and i + x >= n:
				satisfies = False
			if i - x < 0 and i + x < n and (w[i + x] == 0):
				satisfies = False
			if i - x >= 0 and i + x >= n and (w[i - x] == 0):
				satisfies = False
			if i - x >= 0 and i + x < n and (w[i - x] == 0) and (w[i + x] == 0):
				satisfies = False
		if c == '0':
			if i - x >= 0 and w[i - x] == 1:
				satisfies = False
			if i + x < n and w[i + x] == 1:
				satisfies = False
	if satisfies:
		print(*w, sep='')
	else:
		print(-1)


import sys
input = sys.stdin.readline
for kek in range(int(input())):
	s = input()
	x = int(input())
	flg = True
	a = ['1' for j in range(len(s) - 1)]
	for i in range(len(s) - 1):
		if s[i] == '0':
			if i + x < len(s) - 1:
				a[i + x] = '0'
			if i - x >= 0:
				a[i - x] = '0'
	for i in range(len(a)):
		if i - x >= 0 and a[i - x] == '1':
			if s[i] != '1':
				flg = False
		elif i + x < len(a) and a[i + x] == '1':
			if s[i] != '1':
				flg = False
		elif s[i] != '0':
			flg = False
	if flg:
		print(''.join(a))
	else:
		print(-1)


for _ in range(int(input())):
	s = []
	for x in input():
		s.append(int(x))
	n = int(input())
	ans = [None] * len(s)
	for i in range(len(s)):
		if i - n >= 0 and i + n < len(s):
			if s[i] == 0:
				if ans[i - n] == 1:
					ans = -1
					break
				ans[i - n] = ans[i + n] = 0
			elif ans[i - n] == 0:
				ans[i + n] = 1
			else:
				ans[i - n] = 1
		elif i - n < 0 and i + n >= len(s):
			if s[i] == 1:
				ans = -1
				break
		elif i - n >= 0:
			if ans[i - n] == None:
				ans[i - n] = s[i]
			elif ans[i - n] != s[i]:
				ans = -1
				break
		else:
			ans[i + n] = s[i]
	if ans == -1:
		print(-1)
		continue
	for (i, x) in enumerate(ans):
		if x == None:
			x = 1
		ans[i] = str(x)
	print(''.join(ans))


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		x = int(input())
		n = len(s)
		ans = [-1] * n
		for i in range(n):
			if s[i] == '0':
				if i - x > -1:
					ans[i - x] = '0'
				if i + x < n:
					ans[i + x] = '0'
		for i in range(n):
			if ans[i] == -1:
				ans[i] = '1'
		counter = 0
		for i in range(n):
			if s[i] == '1':
				if i - x > -1 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
					continue
				else:
					counter = 1
					break
		if counter:
			print(-1)
		else:
			print(''.join(ans))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if not (i - x >= 0 and w[i - x] == '1') and (not (i + x < len(s) and w[i + x] == '1')):
				print(-1)
				break
	else:
		print(''.join(w))


t = int(input())
for i in range(0, t):
	str1 = input()
	m = int(input())
	l1 = []
	y = len(str1)
	for i in range(0, y):
		l1.append(1)
	for i in range(0, y):
		if str1[i] == '0':
			if i - m >= 0:
				l1[i - m] = 0
			if i + m < y:
				l1[i + m] = 0
	ct = 0
	for i in range(0, y):
		if str1[i] == '1':
			if i - m < 0 and i + m >= y:
				ct += 1
				break
			if i - m < 0:
				if l1[i + m] == 0:
					ct += 1
					break
			if i + m >= y:
				if l1[i - m] == 0:
					ct += 1
					break
			if i - m >= 0 and i + m < y:
				if l1[i - m] == 0 and l1[i + m] == 0:
					ct += 1
					break
	if ct == 0:
		print(*l1, sep='')
	else:
		print('-1')


for test in range(int(input())):
	s = input().strip()
	x = int(input())
	w = [' '] * len(s)
	for (id, val) in enumerate(s):
		if val == '1':
			continue
		if id - x >= 0:
			w[id - x] = '0'
		if id + x < len(s):
			w[id + x] = '0'
	for (id, val) in enumerate(s):
		if val == '0':
			continue
		if (id - x < 0 or w[id - x] == '0') and (id + x >= len(s) or w[id + x] == '0'):
			w = ['-', '1']
			break
		if id - x >= 0 and w[id - x] == ' ':
			w[id - x] = '1'
		if id + x < len(s) and w[id + x] == ' ':
			w[id + x] = '1'
	for i in range(len(w)):
		if w[i] == ' ':
			w[i] = '1'
	print(''.join(w))


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	w = [-1] * len(s)
	for i in range(len(s)):
		ch = s[i]
		if ch == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x < len(s):
				w[i + x] = 0
	for i in range(len(s)):
		ch = s[i]
		if ch == '1':
			if i - x < 0 and i + x >= len(s) or (i - x >= 0 and w[i - x] == 0 and (i + x >= len(s))) or (i - x < 0 and i + x < len(s) and (w[i + x] == 0)) or (i - x >= 0 and i + x < len(s) and (w[i + x] == 0) and (w[i - x] == 0)):
				print(-1)
				break
	else:
		for i in range(len(w)):
			if w[i] == -1:
				w[i] = 1
			w[i] = str(w[i])
		print(''.join(w))


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	num = [1 for i in range(n)]
	f1 = 0
	for i in range(n):
		di = int(s[i])
		if i - x < 0 and i + x >= n:
			if di == 0:
				num[i] = 0
		elif i - x < 0 and i + x < n:
			if di == 0:
				num[i + x] = 0
		elif i - x >= 0 and i + x >= n:
			if di == 0:
				num[i - x] = 0
		elif i - x >= 0 and i + x < n:
			if di == 0:
				num[i - x] = 0
				num[i + x] = 0
	lis = []
	for i in range(n):
		if i - x >= 0 and num[i - x] == 1:
			lis.append(1)
		elif i + x < n and num[i + x] == 1:
			lis.append(1)
		else:
			lis.append(0)
	st = ''
	for i in lis:
		st += str(i)
	if st == s:
		for i in num:
			print(i, end='')
		print()
	else:
		print(-1)


import sys, threading
sys.setrecursionlimit(10 ** 6)
from collections import Counter, defaultdict as dft

def mp():
	return map(int, input().split())

def ml():
	return list(map(int, input().split()))

def main():

	def solve():
		s = input()
		x = int(input())
		n = len(s)
		res = ['0' for i in range(n)]
		for i in range(n):
			if s[i] == '1':
				if i - x >= 0:
					res[i - x] = '1'
				if i + x < n:
					res[i + x] = '1'
		for i in range(n):
			if s[i] == '0':
				if i - x >= 0 and res[i - x] == '1':
					res[i - x] = '0'
				if i + x < n and res[i + x] == '1':
					res[i + x] = '0'
		news = ['0' for i in range(n)]
		for i in range(n):
			if res[i] == '1':
				if i + x < n:
					news[i + x] = '1'
				if i - x >= 0:
					news[i - x] = '1'
		ss = ''.join(news)
		if ss != s:
			return '-1'
		else:
			return ''.join(res)
	t = int(input())
	for _ in range(t):
		print(solve())
sys.setrecursionlimit(10 ** 6)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start()
thread.join()


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	a = ['1' for x in range(len(s))]
	for (i, j) in enumerate(s):
		if s[i] == '0':
			if i >= x:
				a[i - x] = '0'
			if i + x <= n - 1:
				a[i + x] = '0'
	for (a_, b_, c_, d_) in zip(['0'] * x + a, a, a[x:] + ['0'] * x, s):
		if d_ == '1':
			if a_ == '0' and c_ == '0':
				a = ['-1']
				break
	print(*a, sep='')


from sys import stdin, stdout
from collections import defaultdict
import math
input = stdin.readline

def print(x):
	stdout.write(str(x) + '\n')
for _ in range(int(input())):
	s = input().strip()
	x = int(input())
	n = len(s)
	l = [[] for i in range(n)]
	ans = ''
	f = 0
	d = defaultdict(list)
	for i in range(n):
		if i >= x:
			l[i - x].append(i)
			d[i].append(i - x)
		if i + x < n:
			l[i + x].append(i)
			d[i].append(i + x)
		if i < x and i + x >= n and (s[i] != '0'):
			f = 1
	if f == 1:
		print(-1)
		continue
	f = 0
	for i in range(n):
		if len(d[i]) > 1 and s[i] == '1':
			if len(l[i - x]) == 1:
				l[i + x].remove(i)
				d[i].remove(i + x)
			elif len(l[i + x]) == 1:
				l[i - x].remove(i)
				d[i].remove(i - x)
			elif len(l[i + x]) == 2 and s[l[i + x][0]] == s[l[i + x][1]]:
				l[i - x].remove(i)
				d[i].remove(i - x)
			elif len(l[i - x]) == 2 and s[l[i - x][0]] == s[l[i - x][1]]:
				l[i + x].remove(i)
				d[i].remove(i + x)
	for i in range(n):
		if len(d[i]) > 1 and s[i] != '0':
			if len(l[i - x]) == 1:
				l[i + x].remove(i)
				d[i].remove(i + x)
			elif len(l[i + x]) == 1:
				l[i - x].remove(i)
				d[i].remove(i - x)
			elif len(l[i + x]) == 2 and s[l[i + x][0]] == s[l[i + x][1]]:
				l[i - x].remove(i)
				d[i].remove(i - x)
			elif len(l[i - x]) == 2 and s[l[i - x][0]] == s[l[i - x][1]]:
				l[i + x].remove(i)
				d[i].remove(i + x)
	for i in l:
		if len(i) > 1 and s[i[0]] != s[i[1]]:
			f = 1
			break
	if f == 1:
		print(-1)
	else:
		for i in l:
			if len(i) > 0:
				ans += s[i[0]]
			else:
				ans += '1'
		print(ans)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	x = int(input())
	aj = 0
	w = '1' * n
	w = list(w)
	for j in range(n):
		if s[j] == '0':
			if j - x >= 0:
				w[j - x] = '0'
			if j + x < n:
				w[j + x] = '0'
	for j in range(n):
		if s[j] == '1':
			if j - x >= 0 and w[j - x] == '1' or (j + x < n and w[j + x] == '1'):
				a = 5
			else:
				aj = 37
				break
	if aj == 37:
		print(-1)
	else:
		print(''.join(w))


tests = int(input())
for t in range(tests):
	string = list(input())
	x = int(input())
	string_len = len(string)
	res = [-1 for _ in range(string_len)]
	check = True
	for (idx, item) in enumerate(string):
		if item == '0':
			if idx >= x:
				if res[idx - x] == -1 or res[idx - x] == 0:
					res[idx - x] = 0
				else:
					check = False
					break
			if idx <= string_len - x - 1:
				if res[idx + x] == -1 or res[idx + x] == 0:
					res[idx + x] = 0
				else:
					check = False
					break
		if item == '1':
			if idx >= x:
				if res[idx - x] == -1 or res[idx - x] == 1:
					res[idx - x] = 1
				elif idx <= string_len - x - 1 and (res[idx + x] == -1 or res[idx + x] == 1):
					res[idx + x] = 1
				else:
					check = False
					break
			elif idx <= string_len - x - 1:
				if res[idx + x] == -1 or res[idx + x] == 1:
					res[idx + x] = 1
				else:
					check = False
					break
			else:
				check = False
				break
	if not check:
		print(-1)
	else:
		for idx in range(string_len):
			if res[idx] == -1:
				res[idx] = 1
		res = list(map(str, res))
		print(''.join(res))


def fun(s, x):
	n = len(s)
	ans = ''
	for i in range(n):
		if i - x >= 0 and s[i - x] == '1' or (i + x < n and s[i + x] == '1'):
			ans = ans + '1'
		else:
			ans = ans + '0'
	return ans
t = int(input())
while t > 0:
	s = input()
	x = int(input())
	n = len(s)
	flag = 0
	ans = ['1' for _ in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	if fun(ans, x) == s:
		print(''.join(ans))
	else:
		print(-1)
	t -= 1


import math
from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()

def check(w, s):
	global n
	for i in range(n):
		if s[i]:
			if i + x < n or i - x >= 0:
				if not (i + x < n and w[i + x] or (i - x >= 0 and w[i - x])):
					return False
			else:
				return False
	return True
for _ in range(t):
	s = gbs()
	n = len(s)
	(x,) = gil()
	w = [1] * n
	for i in range(n):
		if s[i] == 0:
			if i + x < n:
				w[i + x] = 0
			if i - x >= 0:
				w[i - x] = 0
	if check(w, s):
		for ch in w:
			print(ch, end='')
		print()
	else:
		print(-1)


test = int(input())
for _ in range(test):
	w = list(input())
	x = int(input())
	n = len(w)
	s = [-1] * n
	for i in range(n):
		w[i] = int(w[i])
		if w[i] == 0:
			if i - x >= 0:
				s[i - x] = 0
			if i + x < n:
				s[i + x] = 0
	resflag = True
	for i in range(n):
		if w[i] == 1:
			flag = False
			if i - x >= 0 and s[i - x] != 0:
				flag = True
				s[i - x] = 1
			if i + x < n and s[i + x] != 0:
				flag = True
				s[i + x] = 1
			if flag == False:
				resflag = False
				break
	if resflag:
		for c in s:
			if c == 1 or c == 0:
				print(str(c), end='')
			else:
				print('1', end='')
		print()
	else:
		print(-1)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(int(input())):
	w = input()
	e = len(w)
	x = int(input())
	k = ['1'] * e
	t = ['0'] * e
	for i in range(x, e):
		if w[i] == '0':
			k[i - x] = '0'
	for i in range(e - x):
		if w[i] == '0':
			k[i + x] = '0'
	for i in range(e):
		if i >= x and k[i - x] == '1' or (i + x < e and k[i + x] == '1'):
			t[i] = '1'
	t = ''.join(t)
	k = ''.join(k)
	if t == w:
		print(k)
	else:
		print(-1)


for i in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = ['#'] * n
	flag = True
	for j in range(n):
		if j + 1 - x <= 0:
			if j + 1 + x > n:
				if s[j] == '1':
					flag = False
					break
			elif s[j] == '0':
				if w[j + x] not in ['0', '#']:
					flag = False
					break
				w[j + x] = '0'
			else:
				if w[j + x] not in ['1', '#']:
					flag = False
					break
				w[j + x] = '1'
		elif j + 1 + x > n:
			if s[j] == '0':
				if w[j - x] not in ['0', '#']:
					flag = False
					break
				w[j - x] = '0'
			else:
				if w[j - x] not in ['1', '#']:
					flag = False
					break
				w[j - x] = '1'
		elif s[j] == '0':
			if w[j + x] not in ['#', '0'] or w[j - x] not in ['#', '0']:
				flag = False
				break
			w[j + x] = w[j - x] = '0'
		elif w[j + x] == '0':
			if w[j - x] == '0':
				flag = False
				break
			w[j - x] = '1'
		elif w[j - x] == '0':
			w[j + x] = '1'
	if not flag:
		print(-1)
		continue
	for j in range(n):
		if w[j] == '#':
			w[j] = '1'
	print(''.join(w))


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	s = input()
	n = len(s)
	x = int(input())
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		c = 0
		if i - x >= 0:
			c |= int(ans[i - x])
		if i + x < n:
			c |= int(ans[i + x])
		if s[i] == '1' and (not c):
			print(-1)
			return
		if s[i] == '0' and c:
			print(-1)
			return
	print(''.join(ans))
	return
t = 1
t = int(input())
for _ in range(t):
	main()


t = int(input())
while t > 0:
	t -= 1
	s = input().strip()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	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'
	ans = ''
	for i in range(n):
		k = '0'
		if i + x < n and w[i + x] == '1':
			k = '1'
		if i - x >= 0 and w[i - x] == '1':
			k = '1'
		ans += k
	if ans == s:
		print(''.join(w))
	else:
		print(-1)


for _ in range(int(input())):
	s = str(input())
	n = int(input())
	l = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - n >= 0:
				l[i - n] = 0
			if i + n < len(s):
				l[i + n] = 0
	a = ''
	for i in range(len(l)):
		a = a + str(l[i])
	t = ''
	k = 0
	for i in range(len(a)):
		if i - n >= 0 and a[i - n] == '1':
			k = 1
		if i + n < len(l) and a[i + n] == '1':
			k = 1
		t = t + str(k)
		k = 0
	if t == s:
		print(a)
	else:
		print(-1)


for u in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	d = ['1'] * n
	f = 0
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				d[i + x] = '0'
			if i - x >= 0:
				d[i - x] = '0'
	for i in range(n):
		c = 0
		if s[i] == '1':
			if i + x < n:
				if d[i + x] == '1':
					c = 1
			if i - x >= 0:
				if d[i - x] == '1':
					c = 1
			if c == 0:
				f = 1
				break
	if f == 0:
		print(''.join(d))
	else:
		print(-1)


import math
from decimal import *
import random
for _ in range(int(input())):
	s = str(input())
	x = int(input())
	ans = ['1' for i in range(len(s))]
	ok = True
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < len(s):
				ans[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			al = False
			if i - x >= 0:
				if ans[i - x] == '1':
					al = True
			if i + x < len(s):
				if ans[i + x] == '1':
					al = True
			if not al:
				ok = False
	if not ok:
		print(-1)
	else:
		print(''.join(ans))


t = int(input())
for i in range(t):
	s = input().strip()
	x = int(input())
	n = len(s)
	a = [-1] * n
	for j in range(n):
		if s[j] == '0':
			q = 0
			if j - x >= 0:
				a[j - x] = 0
			else:
				q = q + 1
			if j + x < n:
				a[j + x] = 0
			else:
				q = q + 1
			if q == 2:
				a[j] = 0
	f = 0
	for j in range(n):
		if s[j] == '1':
			c = 0
			if j - x >= 0 and a[j - x] != 0:
				c = c + 1
				a[j - x] = 1
			if j + x < n and a[j + x] != 0:
				c = c + 1
				a[j + x] = 1
			if c == 0:
				f = 1
				break
	if f == 1:
		print(-1)
	elif -1 in a:
		print(-1)
	else:
		print(''.join(map(str, a)))


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	x = int(input())
	w = ['0'] * n
	c = 1
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0:
				w[i - x] = '1'
			if i + x < n:
				w[i + x] = '1'
	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'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
				continue
			else:
				c = 0
				break
	if c:
		print(''.join(w))
	else:
		print(-1)


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	s = input()
	n = len(s) - 1
	x = int(input())
	pocz = ['1'] * n
	for i in range(n):
		if i - x >= 0 and s[i - x] == '0':
			pocz[i] = '0'
		if i + x < n and s[i + x] == '0':
			pocz[i] = '0'
	odp = True
	for i in range(n):
		if s[i] == '1':
			dupa = []
			if i - x >= 0:
				dupa.append(pocz[i - x])
			if i + x < n:
				dupa.append(pocz[i + x])
			if dupa.count('1') == 0:
				odp = False
	if odp:
		print(''.join(pocz))
	else:
		print(-1)


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def Printer(arr):
	for i in range(n):
		print(arr[i], end='')
	print()

def Checker(ans):
	nans = ''
	for i in range(n):
		if i + x < n and i - x >= 0:
			if ans[i + x] == '1' or ans[i - x] == '1':
				if s[i] != '1':
					return False
			elif s[i] != '0':
				return False
		elif i + x < n:
			if ans[i + x] == '1':
				if s[i] != '1':
					return False
			elif s[i] != '0':
				return False
		elif i - x >= 0:
			if ans[i - x] == '1':
				if s[i] != '1':
					return False
			elif s[i] != '0':
				return False
		elif s[i] == '1':
			return False
	return True
t = int(input())
while t:
	t -= 1
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	if Checker(ans):
		Printer(ans)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	f = True
	f1 = '0'
	f2 = '0'
	s = input()
	x = int(input())
	n = len(s)
	res = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				res[i + x] = '0'
			if i - x >= 0:
				res[i - x] = '0'
	for i in range(n):
		f1 = '0'
		f2 = '0'
		if i + x < n and res[i + x] == '1':
			f1 = '1'
		if i - x >= 0 and res[i - x] == '1':
			f2 = '1'
		f = True if max(f1, f2) == s[i] else False
		if not f:
			break
	print(''.join(res) if f else -1)


t = int(input().split()[0])
for case in range(t):
	s = list(input().split()[0])
	x = int(input().split()[0])
	original = list('1' * len(s))
	for c in range(len(s)):
		if s[c] == '0':
			if c - x >= 0:
				original[c - x] = '0'
			if c + x < len(s):
				original[c + x] = '0'
	check = []
	for c in range(len(s)):
		curr = '0'
		if c - x >= 0 and original[c - x] == '1':
			curr = '1'
		if c + x < len(s) and original[c + x] == '1':
			curr = '1'
		check.append(curr)
	if check == s:
		print(''.join(original))
	else:
		print('-1')


for i in range(int(input())):
	old_string = input()
	x = int(input())
	n = len(old_string)
	new_string = [1] * n
	for j in range(n):
		if old_string[j] == '0':
			if j >= x:
				new_string[j - x] = 0
			if j + x < n:
				new_string[j + x] = 0
	good = True
	for j in range(n):
		if old_string[j] == '1':
			good = False
			if j >= x and new_string[j - x] == 1:
				good = True
			if j + x < n and new_string[j + x] == 1:
				good = True
			if not good:
				print('-1')
				break
	if good:
		print(''.join(map(str, new_string)))


import io, os
from collections import deque
import bisect
RL = lambda : list(map(int, input().split(' ')))
T = int(input())
for _ in range(T):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * len(s)
	flag = 1
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			f1 = 0
			f2 = 0
			if i - x >= 0:
				if w[i - x] == '1':
					f1 = 1
			if i + x < n:
				if w[i + x] == '1':
					f2 = 1
			if f1 == 0 and f2 == 0:
				flag = 0
	if flag == 0:
		print(-1)
	else:
		print(''.join(w))


tests = int(input())
for _ in range(tests):
	string = list(input())
	n = len(string)
	x = int(input())
	ans = list(n * '1')
	for i in range(n):
		if string[i] == '0':
			if i + x < n:
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	check = []
	for i in range(n):
		number = '0'
		if i - x >= 0 and ans[i - x] == '1':
			number = '1'
		if i + x < n and ans[i + x] == '1':
			number = '1'
		check.append(number)
	if check == string:
		print(''.join(ans))
	else:
		print('-1')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	l = [0] + li3()
	x = val()
	n = len(l) - 1
	ans = [None] * (n + 1)
	flag = 0
	for i in range(1, n + 1):
		if l[i] == 1:
			if i > x and (ans[i - x] == 1 or ans[i - x] == None):
				ans[i - x] = 1
			elif i + x <= n:
				ans[i + x] = 1
			else:
				flag = 1
				break
		elif (i <= x or (ans[i - x] == None or ans[i - x] == 0)) and (i + x > n or ans[i + x] == None):
			if i > x:
				ans[i - x] = 0
			if i + x <= n:
				ans[i + x] = 0
		else:
			flag = 1
			break
	for i in range(1, n + 1):
		if ans[i] == None:
			ans[i] = 1
	if flag:
		print(-1)
	else:
		print(*ans[1:n + 1], sep='')


def process(n, x):
	l = [0 for i in range(len(n))]
	for i in range(len(l)):
		if i - x >= 0 and n[i - x] == 1:
			l[i] = 1
		if i + x < len(l) and n[i + x] == 1:
			l[i] = 1
	return l
for t in range(int(input())):
	l = list(map(int, list(input())))
	x = int(input())
	n = [1 for i in range(len(l))]
	for i in range(len(n)):
		if l[i] == 0:
			if i + x < len(n):
				n[i + x] = 0
			if i - x > -1:
				n[i - x] = 0
	if process(n, x) != l:
		print(-1)
	else:
		print(''.join(map(str, n)))


for _ in range(int(input())):
	s = str(input())
	x = int(input())
	n = len(s)
	c = [1 for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				c[i - x] = 0
			if i + x < n:
				c[i + x] = 0
	flag = False
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and c[i - x] == 1 or (i + x < n and c[i + x] == 1):
				pass
			else:
				flag = True
				break
	if flag == True:
		print(-1)
	else:
		print(''.join((str(i) for i in c)))


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	n = len(s)
	ans = ''
	flag = 1
	for i in range(n):
		if i < x and i < n - x:
			if s[i + x] == '1':
				ans += '1'
			else:
				ans += '0'
		elif i >= n - x and i >= x:
			if s[i - x] == '1':
				ans += '1'
			else:
				ans += '0'
		elif i - x < 0 and i + x >= n:
			ans += '0'
		elif s[i - x] == '0' and s[i + x] == '0':
			ans += '0'
		elif s[i - x] == '1' and s[i + x] == '1':
			ans += '1'
		else:
			ans += '0'
	for i in range(n):
		if s[i] == '0':
			if i < x and i < n - x:
				if ans[i + x] != '0':
					flag = 0
					break
			elif i >= n - x and i >= x:
				if ans[i - x] != '0':
					flag = 0
					break
			elif i - x < 0 and i + x >= 0:
				pass
			elif ans[i + x] == '1' or ans[i - x] == '1':
				flag = 0
				break
		elif i < x and i < n - x:
			if ans[i + x] != '1':
				flag = 0
				break
		elif i >= n - x and i >= x:
			if ans[i - x] != '1':
				flag = 0
				break
		elif i - x < 0 and i + x >= 0:
			flag = 0
			break
		elif ans[i + x] == '0' and ans[i - x] == '0':
			flag = 0
			break
	if flag:
		print(ans)
	else:
		print(-1)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		s = input()
		n = len(s)
		ans = ['1' for x in range(n)]
		x = I()
		flag = 0
		for i in range(n):
			if s[i] == '0':
				if i - x >= 0:
					ans[i - x] = '0'
				if i + x < n:
					ans[i + x] = '0'
		for i in range(n):
			if s[i] == '1':
				if i - x >= 0:
					if ans[i - x] == '1':
						continue
				if i + x < n:
					if ans[i + x] == '1':
						continue
				flag = 1
		if flag:
			print(-1)
		else:
			print(''.join(ans))
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


for _ in range(int(input())):
	s = list(map(int, input()))
	x = int(input())
	n = len(s)
	w = [1] * n
	for i in range(n):
		if s[i] == 0:
			if i >= x:
				w[i - x] = s[i]
			if i + x < n:
				w[i + x] = s[i]
		is_there = 1
	for i in range(n):
		if s[i] == 1:
			if (i - x < 0 or w[i - x] == 0) and (i + x >= n or w[i + x] == 0):
				is_there = 0
				break
	if is_there == 0:
		print(-1)
	else:
		print(''.join([str(x) for x in w]))


import sys
sys.setrecursionlimit(2147483647)

def solve(s, x):
	l = len(s)
	ans = [1] * l
	flags = [0] * l
	point = 0
	searched = -1
	for point in range(l):
		a = s[point]
		if a == '0':
			if point - x >= 0:
				if flags[point - x]:
					if ans[point - x] != 0:
						return -1
				else:
					ans[point - x] = 0
					flags[point - x] = 1
			if point + x < l:
				ans[point + x] = 0
				flags[point + x] = 1
		elif point - x < 0:
			if point + x >= l:
				return -1
			else:
				ans[point + x] = 1
				flags[point + x] = 1
		elif point - 2 * x < 0:
			ans[point - x] = 1
			flags[point - x] = 1
		elif flags[point - x] and ans[point - x] == 0:
			if point + x >= l:
				return -1
			else:
				ans[point + x] = 1
				flags[point + x] = 1
		else:
			ans[point - x] = 1
			flags[point - x] = 1
	return ''.join(list(map(str, ans)))

def main():
	t = int(input())
	ans = []
	for _ in range(t):
		s = input()
		x = int(input())
		ans.append(solve(s, x))
	for r in ans:
		print(r)
main()


t = int(input())
for qwerty in range(t):
	s = input()
	k = int(input())
	n = len(s)
	ans = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - k >= 0:
				ans[i - k] = '0'
			if i + k < n:
				ans[i + k] = '0'
	v = ''
	for i in range(n):
		if i - k >= 0:
			if ans[i - k] == '1':
				v += '1'
			elif i + k < n:
				if ans[i + k] == '1':
					v += '1'
				else:
					v += '0'
			else:
				v += '0'
		elif i + k < n:
			if ans[i + k] == '1':
				v += '1'
			else:
				v += '0'
		else:
			v += '0'
	if v != s:
		print('-1')
	else:
		for i in range(n):
			print(ans[i], end='')
		print()


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	s = I1().strip()
	x = int(I1())
	n = len(s)
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	s1 = ''
	for i in range(n):
		if i >= x and w[i - x] == '1':
			s1 += '1'
		elif i + x < n and w[i + x] == '1':
			s1 += '1'
		else:
			s1 += '0'
	if s == s1:
		print(''.join(w))
	else:
		print(-1)


def solve():
	s = input()
	x = int(input())
	w = ['.'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] != '0':
				w[i - x] = '1'
				continue
			if i + x < len(s) and w[i + x] != '0':
				w[i + x] = '1'
				continue
			print(-1)
			return
	for i in range(len(s)):
		if w[i] == '.':
			w[i] = '1'
	print(*w, sep='')
for t in range(int(input())):
	solve()


import math
num_cases = int(input())
for _ in range(num_cases):
	s = input().strip()
	x = int(input())
	n = len(s)
	w = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '1':
			continue
		if i + x < n:
			w[i + x] = '0'
		if i - x >= 0:
			w[i - x] = '0'
	poss = 1
	for i in range(n):
		if s[i] == '0':
			continue
		if not (i + x < n and w[i + x] == '1' or (i - x >= 0 and w[i - x] == '1')):
			poss = 0
			break
	if poss == 0:
		print(-1)
	else:
		print(''.join(w))


T = int(input())
ans = []
for i in range(T):
	s = list(input())
	x = int(input())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	is_Ok = True
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0:
				if w[i - x] == '1':
					continue
			if i + x < len(s):
				if w[i + x] == '1':
					continue
			is_Ok = False
	if is_Ok:
		ans.append(w)
	else:
		ans.append(['-1'])
for i in range(T):
	print(''.join(ans[i]))


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())

def solve():
	s = inp()
	x = itg()
	n = len(s)
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if 0 <= i - x < n:
				w[i - x] = '0'
			if 0 <= i + x < n:
				w[i + x] = '0'
	w = ''.join(w)
	for i in range(n):
		if s[i] == '1':
			if not (0 <= i - x < n and w[i - x] == '1' or (0 <= i + x < n and w[i + x] == '1')):
				return '-1'
	return w
for __ in range(itg()):
	print(solve())


t = int(input())
while t:
	s = input()
	n = len(s)
	x = int(input())
	a = ['_' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				a[i - x] = '0'
			if i + x < n:
				a[i + x] = '0'
	flag = True
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and a[i - x] == '_':
				a[i - x] = '1'
			if i + x < n and a[i + x] == '_':
				a[i + x] = '1'
			if (i < x or a[i - x] == '0') and (i + x >= n or a[i + x] == '0'):
				flag = False
				break
	if not flag:
		print(-1)
	else:
		for i in range(n):
			if a[i] == '_':
				a[i] = '0'
		print(''.join(a))
	t -= 1


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
letters = ascii_letters[:26]
input = stdin.readline
for _ in range(int(input())):
	arr = input().strip()
	x = int(input())
	n = len(arr)
	res = ['-'] * n
	for i in range(n):
		if arr[i] == '0':
			if i + x < n:
				res[i + x] = '0'
			if i - x >= 0:
				res[i - x] = '0'
	can = True
	for i in range(n):
		if arr[i] != '1':
			continue
		bf = []
		was = False
		if i + x < n:
			if res[i + x] == '-':
				res[i + x] = '1'
			if res[i + x] == '1':
				was = True
		if i - x >= 0:
			if res[i - x] == '-':
				res[i - x] = '1'
			if res[i - x] == '1':
				was = True
		if not was:
			can = False
	if not can:
		print(-1)
	else:
		for i in range(n):
			if res[i] == '-':
				res[i] = '0'
		print(''.join(res))


import sys
input = sys.stdin.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	for _ in range(int(input())):
		s = input().strip()
		x = int(input())
		place = [2] * len(s)
		fail = False
		for i in range(len(s)):
			if i + x > len(s) - 1 and i - x < 0:
				if s[i] == '1':
					fail = True
					break
			elif i + x > len(s) - 1:
				if s[i] == '0':
					if place[i - x] == 1:
						fail = True
						break
					place[i - x] = 0
				else:
					if place[i - x] == 0:
						fail = True
						break
					place[i - x] = 1
			elif i - x < 0:
				if s[i] == '0':
					if place[i + x] == 1:
						fail = True
						break
					place[i + x] = 0
				else:
					if place[i + x] == 0:
						fail = True
						break
					place[i + x] = 1
			elif s[i] == '0':
				if place[i + x] == 1:
					fail = True
					break
				place[i + x] = 0
				if place[i - x] == 1:
					fail = True
					break
				place[i - x] = 0
		for i in range(len(s)):
			if i - x >= 0 and i + x <= len(s) - 1 and (s[i] == '1'):
				if place[i + x] == 0 and place[i - x] == 0:
					fail = True
					break
		if fail:
			print(-1)
		else:
			output = ['1'] * len(s)
			for i in range(len(s)):
				if place[i] == 0:
					output[i] = '0'
			print(''.join(output))
prog()


for _ in range(int(input())):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	f = True
	if x >= len(s):
		print(-1)
	else:
		for i in range(len(s)):
			if s[i] == '0':
				if i - x >= 0:
					w[i - x] = '0'
				if i + x < len(s):
					w[i + x] = '0'
		chec = ['0'] * len(s)
		for i in range(len(s)):
			if i - x >= 0 and w[i - x] == '1':
				chec[i] = '1'
			if i + x < len(s) and w[i + x] == '1':
				chec[i] = '1'
		if ''.join(chec) == s:
			print(*w, sep='')
		else:
			print(-1)


import sys
ll = lambda : list(map(int, input().split()))
lls = lambda : list(map(str, input().split()))
fin = lambda : list(map(float, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
mod = 10 ** 9 + 7
from math import *
from datetime import datetime
from collections import *
import math
for _ in range(ii()):
	s = st()
	x = ii()
	ans = ['1'] * len(s)
	f = 1
	for i in range(len(s)):
		if i - x < 0 and i + x >= len(s):
			ans[i] = '0'
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < len(s):
				ans[i + x] = '0'
	sol = ['0'] * len(s)
	for i in range(len(s)):
		if i - x >= 0 and ans[i - x] == '1' or (i + x < len(s) and ans[i + x] == '1'):
			sol[i] = '1'
	if s == ''.join(sol):
		print(''.join(ans))
	else:
		print(-1)


import sys
t = int(input())

def solve():
	w = input()
	n = len(w)
	x = int(input())
	print('[LOG] solve(w=', w, ', x=', x, ')', file=sys.stderr)

	def is_zero(pos):
		if pos <= 0 or pos > n:
			return True
		before = pos + x <= n and w[pos + x - 1] == '0'
		after = pos - x >= 1 and w[pos - x - 1] == '0'
		print('[LOG] is_zero(', pos, ') returns (', before, ', ', after, ') =', before or after, file=sys.stderr)
		return before or after
	for i in range(1, n + 1):
		if w[i - 1] == '1':
			if is_zero(i - x) and is_zero(i + x):
				print(-1)
				break
	else:
		for i in range(1, n + 1):
			print(0 if is_zero(i) else 1, end='')
		print()
for _ in range(t):
	solve()


n = int(input())
for i in range(n):
	s = str(input())
	x = int(input())
	w = ['1'] * len(s)
	for j in range(len(s)):
		if j - x >= 0 and s[j] == '0':
			w[j - x] = '0'
		if j + x < len(s) and s[j] == '0':
			w[j + x] = '0'
	ans = 0
	for j in range(len(s)):
		if s[j] == '1':
			if j - x >= 0 and w[j - x] == '1' or (j + x < len(s) and w[j + x] == '1'):
				pass
			else:
				ans = 1
	if ans == 1:
		print(-1)
	else:
		print(''.join(w))


n = int(input())
for i in range(n):
	s = input()
	t = int(input())
	w = ['1'] * len(s)
	flag = True
	for i in range(len(s)):
		if s[i] == '0':
			if i - t > -1:
				w[i - t] = '0'
			if i + t < len(s):
				w[i + t] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			if i - t > -1 and w[i - t] == '1' or (i + t < len(s) and w[i + t] == '1'):
				continue
			else:
				print(-1)
				flag = False
				break
		elif i - t > -1 and w[i - t] == '1' or (i + t < len(s) and w[i + t] == '1'):
			print(-1)
			flag = False
			break
	if flag:
		print(''.join(w))


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	ls = [0 for i in range(x)]
	out = [0 for i in range(x)]
	for i in s:
		ls.append(int(i))
		out.append(1)
	for i in range(x):
		ls.append(0)
		out.append(0)
	for i in range(x, x + n):
		if ls[i] == 0:
			(out[i - x], out[i + x]) = (0, 0)
	poss = 1
	for i in range(x, x + n):
		if ls[i]:
			if out[i - x] + out[i + x] == 0:
				poss = 0
				break
	if poss == 0:
		print(-1)
	else:
		for i in range(x, x + n):
			print(out[i], end='')
		print()


t = int(input())

def solve(s, x):
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < len(s):
				ans[i + x] = '0'
	for i in range(len(s)):
		if (ans[i + x] == '0' if i + x < len(s) else True) and (ans[i - x] == '0' if i - x >= 0 else True) and (s[i] == '1'):
			print(-1)
			break
	else:
		print(''.join(ans))
for i in range(t):
	solve(input(), int(input()))


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	w = [-1 for i in range(n)]
	x = int(input())
	possible = True
	for i in range(n):
		imx = i - x
		ipx = i + x
		if s[i] == '1':
			if imx >= 0 and w[imx] == -1:
				w[imx] = '1'
			if ipx < n:
				w[ipx] = '1'
		else:
			if imx >= 0:
				w[imx] = '0'
			if ipx < n:
				w[ipx] = '0'
	for i in range(n):
		if w[i] == -1:
			w[i] = '0'
	for i in range(n):
		ipx = i + x
		imx = i - x
		if s[i] == '1':
			if imx >= 0 and ipx < n and (w[imx] != '1') and (w[ipx] != '1'):
				possible = not possible
				break
			elif imx >= 0 and ipx >= n and (w[imx] != '1'):
				possible = not possible
				break
			elif ipx < n and imx < 0 and (w[ipx] != '1'):
				possible = not possible
				break
			elif ipx >= n and imx < 0:
				possible = not possible
				break
		elif imx >= 0 and ipx < n and (w[imx] != '0' or w[ipx] != '0'):
			possible = not possible
			break
		elif imx >= 0 and ipx >= n and (w[imx] != '0'):
			possible = not possible
			break
		elif ipx < n and imx < 0 and (w[ipx] != '0'):
			possible = not possible
			break
	if not possible:
		print(-1)
	else:
		print(''.join(w))


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = [1] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	c = 0
	for i in range(n):
		if s[i] == '1':
			if i >= x and ans[i - x] == 1 or (i + x < n and ans[i + x] == 1):
				continue
			else:
				c = 1
				break
		else:
			if i >= x and ans[i - x] == 1:
				c = 1
				break
			if i + x < n and ans[i + x] == 1:
				c = 1
				break
	if c == 0:
		for i in ans:
			print(i, end='')
	else:
		print(-1, end='')
	print()


import sys
import math
import collections
import bisect
import itertools
import decimal
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
ni = lambda : int(sys.stdin.readline().rstrip())
ns = lambda : map(int, sys.stdin.readline().rstrip().split())
na = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda : list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))

def main():
	t = ni()
	for _ in range(t):
		s = input()
		x = ni()
		ans = [1 for _ in range(len(s))]
		for (i, si) in enumerate(s):
			if si == '0':
				if i - x >= 0:
					ans[i - x] = 0
				if i + x < len(s):
					ans[i + x] = 0
		flg = True
		for (i, si) in enumerate(s):
			if si == '1':
				(flg1, flg2) = (False, False)
				if i - x >= 0:
					flg1 = ans[i - x]
				if i + x < len(s):
					flg2 = ans[i + x]
				if not (flg1 or flg2):
					flg = False
					break
		if flg:
			print(*ans, sep='')
		else:
			print(-1)
main()


t = int(input())
for i in range(t):
	s = input()
	x = int(input())
	n = len(s)
	dp = [None for i in range(len(s))]
	for i in range(n):
		ans = 1
		if i - x >= 0:
			ans &= int(s[i - x])
		if i + x < n:
			ans &= int(s[i + x])
		dp[i] = ans
	flag = 0
	for i in range(n):
		ans = 0
		if i - x >= 0:
			ans |= dp[i - x]
		if i + x < n:
			ans |= dp[i + x]
		if ans != int(s[i]):
			flag = 1
			break
	if flag == 1:
		print('-1')
	else:
		print(''.join([str(k) for k in dp]))


import sys
input = sys.stdin.readline

def process():
	s = input().strip()
	(x,) = map(int, input().split())
	n = len(s)
	t = [1] * n
	for i in range(n):
		if int(s[i]) == 0:
			if i - x >= 0:
				t[i - x] = 0
			if i + x < n:
				t[i + x] = 0
	for i in range(n):
		if int(s[i]) == 1:
			r = 0
			if i - x >= 0:
				if t[i - x] == 1:
					r = 1
			if i + x < n:
				if t[i + x] == 1:
					r = 1
			if not r:
				print(-1)
				return
	print(''.join((str(c) for c in t)))
(T,) = map(int, input().split())
for _ in range(T):
	process()


def solve():
	T = int(input())

	def f(s, x):
		res = ['0' for i in range(len(s))]
		for i in range(len(res)):
			if i - x >= 0 and s[i - x] == '1' or (i + x < len(s) and s[i + x] == '1'):
				res[i] = '1'
			else:
				res[i] = '0'
		return ''.join(res)
	for i in range(T):
		w = input()
		x = int(input())
		n = len(w)
		s = ['1' for _ in range(n)]
		for (i, c) in enumerate(w):
			(l_index, r_index) = (i - x, i + x)
			if c == '0':
				if l_index >= 0:
					s[l_index] = '0'
				if r_index < n:
					s[r_index] = '0'
		ns = ''.join(s)
		if f(ns, x) == w:
			print(ns)
		else:
			print(str(-1))
solve()


t = int(input())
for _ in range(t):
	st = [int(x) for x in input()]
	x = int(input())
	arr = [1 for _ in st]
	n = len(st)
	for i in range(len(st)):
		if st[i] == 0:
			if i - x >= 0:
				arr[i - x] = 0
			if i + x < len(st):
				arr[i + x] = 0
	st1 = [0 for _ in st]
	for i in range(len(st)):
		if arr[i] == 1:
			if i - x >= 0:
				st1[i - x] = 1
			if i + x < len(st):
				st1[i + x] = 1
	if st1 == st:
		for i in arr:
			print(i, end='')
		print()
		continue
	print('-1')


t = int(input())
while t:
	s = input()
	n = len(s)
	x = int(input())
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	sdash = ''
	for i in range(n):
		if i + x < n:
			if ans[i + x] == '1':
				sdash += '1'
				continue
		if i - x >= 0:
			if ans[i - x] == '1':
				sdash += '1'
				continue
		sdash += '0'
	if s == sdash:
		print(''.join(ans))
	else:
		print(-1)
	t -= 1


cases = int(input())

def solve():
	w = str(input())
	x = int(input())
	n = len(w)
	s = list('1' * n)
	for i in range(n):
		if w[i] == '0':
			if i - x >= 0:
				s[i - x] = '0'
			if i + x < n:
				s[i + x] = '0'
	for i in range(n):
		one = False
		one = one or (i - x >= 0 and s[i - x] == '1')
		one = one or (i + x < n and s[i + x] == '1')
		if one:
			a = '0'
		if not one:
			a = '1'
		if w[i] == a:
			print(-1)
			return
	print(''.join(s))
while cases:
	solve()
	cases -= 1


import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip('\n')
	x = int(stdin.readline())
	n = len(s)
	a = [-1] * n
	chk = True
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and a[i - x] != 0:
				a[i - x] = 1
				continue
			if i + x < n:
				if a[i + x] == 0:
					chk = False
					break
				else:
					a[i + x] = 1
					continue
			chk = False
			break
		else:
			if i - x >= 0:
				if a[i - x] == 1:
					chk = False
					break
				else:
					a[i - x] = 0
			if i + x < n:
				if a[i + x] == 1:
					chk = False
					break
				else:
					a[i + x] = 0
	if not chk:
		print(-1)
		continue
	w = ''
	for i in range(n):
		if a[i] != -1:
			w += str(a[i])
		else:
			w += '1'
	print(w)


t = int(input())
for i in range(t):
	s = str(input())
	x = int(input())
	n = len(s)
	lis = [-1] * n
	z = 0
	for j in range(n):
		if s[j] == '0':
			if j + x <= n - 1:
				lis[j + x] = 0
			if j - x >= 0:
				lis[j - x] = 0
	for j in range(n):
		if s[j] == '1':
			if j - x >= 0 and j + x <= n - 1:
				if lis[j - x] == 0 and lis[j + x] == 0:
					z += 1
					break
				elif lis[j - x] == 0 and lis[j + x] != 0:
					lis[j + x] = 1
				elif lis[j - x] != 0 and lis[j + x] == 0:
					lis[j - x] = 1
				elif lis[j - x] != 0 and lis[j + x] != 0:
					lis[j - x] = 1
			elif j - x >= 0 and j + x > n - 1:
				if lis[j - x] == 0:
					z += 1
					break
				else:
					lis[j - x] = 1
			elif j - x < 0 and j + x <= n - 1:
				if lis[j + x] == 0:
					z += 1
					break
				else:
					lis[j + x] = 1
			else:
				z += 1
				break
	if z == 1:
		print(-1)
	else:
		ans = ''
		for j in range(n):
			if lis[j] == -1:
				ans += '1'
			else:
				ans += str(lis[j])
		print(ans)


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prdbg(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
	pass

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	s = get_str()
	x = oint()
	n = len(s)
	w = [-1] * n
	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
	flag = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == -1 or (i + x < n and w[i + x] == -1):
				pass
			else:
				flag = 1
	if flag:
		print(-1)
		continue
	for i in range(n):
		if w[i] == -1:
			w[i] = 1
	print(''.join(map(str, w)))


UNDEF = '?'

def forward(w, x):
	s = ['?'] * len(w)
	for i in range(len(w)):
		if i - x >= 0 and w[i - x] == '1':
			s[i] = '1'
		elif i + x < len(w) and w[i + x] == '1':
			s[i] = '1'
		else:
			s[i] = '0'
	return ''.join(s)

def solve(s, x):
	n = len(s)
	w = [UNDEF] * n
	for j in range(x):
		if j + x < n:
			w[j + x] = s[j]
		i = n - j - 1
		if i - x >= 0:
			if w[i - x] != UNDEF and w[i - x] != s[i]:
				return UNDEF
			w[i - x] = s[i]
	for i in range(x, n - x):
		if s[i] == '0':
			if '1' in (w[i - x], w[i + x]):
				return UNDEF
			w[i - x] = '0'
			w[i + x] = '0'
	w = ''.join(w).replace('?', '1')
	return w if forward(w, x) == s else UNDEF
for _ in range(int(input())):
	s = input()
	x = int(input())
	ans = solve(s, x)
	if ans == UNDEF:
		print(-1)
	else:
		print(ans)


for _ in range(int(input())):
	s = input()
	x = int(input())
	w = []
	w = [-1] * len(s)
	n = len(s)
	flag = False
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x <= n - 1:
				w[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0:
				if w[i - x] == 0:
					if i + x < n:
						if w[i + x] == 0:
							flag = True
							break
					else:
						flag = True
						break
			elif i + x < n:
				if w[i + x] == 0:
					flag = True
					break
			else:
				flag = True
				break
	if flag:
		print(-1)
	else:
		for i in range(n):
			if w[i] == -1:
				w[i] = 1
			print(w[i], end='')
		print()


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))
MOD = 10 ** 9 + 7

def main():
	T = int(rl())
	for _ in range(T):
		s = [int(d) for d in list(rll()[0])]
		x = int(rl())
		n = len(s)
		w = [1 for _ in range(n)]
		for (i, d) in enumerate(s):
			if d == 0:
				if i - x >= 0:
					w[i - x] = 0
				if i + x < n:
					w[i + x] = 0
		exists = True
		for (i, d) in enumerate(w):
			if s[i] == 0:
				continue
			flag = False
			L = w[i - x] if i - x >= 0 else None
			R = w[i + x] if i + x < n else None
			if i - x >= 0 and w[i - x] == 1:
				flag = True
			elif i + x < n and w[i + x] == 1:
				flag = True
			if not flag:
				exists = False
		if not exists:
			print(-1)
		else:
			print(''.join((str(d) for d in w)))
	stdout.close()
main()


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	ans = ['1'] * n
	f = 0
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			c = 0
			kk = 0
			if i - x >= 0 and ans[i - x] == '1':
				c += 1
			if i + x < n and ans[i + x] == '1':
				c += 1
			if c == 0:
				f = 1
				break
	if f:
		print(-1)
	else:
		print(''.join(ans))


n = int(input())
for i in range(1, n + 1):
	s = input()
	nn = len(s)
	x = int(input())
	ans = '1' * nn
	for i in range(nn):
		if s[i] == '0':
			if i - x >= 0:
				index = i - x
				ans = ans[:index] + '0' + ans[index + 1:]
			if i + x < nn:
				index = i + x
				ans = ans[:index] + '0' + ans[index + 1:]
	ff = 0
	for i in range(nn):
		flag = False
		flag = flag or (i - x >= 0 and ans[i - x] == '1')
		flag = flag or (i + x < nn and ans[i + x] == '1')
		if not flag:
			if s[i] == '1':
				print('-1')
				ff = 1
				break
	if ff == 0:
		print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	S = input()
	N = len(S)
	x = INT()
	W = [''] * N
	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'
	for i in range(N):
		if not W[i]:
			W[i] = '1'
	ok = True
	for i in range(N):
		if S[i] == '1':
			if (i - x < 0 or W[i - x] == '0') and (i + x >= N or W[i + x] == '0'):
				ok = False
				break
	if ok:
		ans = ''.join(W)
		print(ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = input().strip()
	x = int(input())
	w = ['1'] * len(s)
	for (i, digit) in enumerate(s):
		if digit == '1':
			continue
		j = i - x
		if j >= 0:
			w[j] = '0'
		j = i + x
		if j < len(s):
			w[j] = '0'
	new_s = ['0'] * len(s)
	for i in range(len(s)):
		j = i - x
		if j >= 0 and w[j] == '1':
			new_s[i] = '1'
		j = i + x
		if j < len(s) and w[j] == '1':
			new_s[i] = '1'
	if ''.join(new_s) != s:
		print(-1)
	else:
		print(''.join(w))


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	w = [-1] * len(s)
	n = len(s)
	flag = 0
	for i in range(0, n):
		if s[i] == '0':
			if i - x >= 0:
				w[i - x] = 0
			if i + x < n:
				w[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and i + x < n:
				if w[i - x] == 0 and w[i + x] == 0:
					flag = 1
					break
				if w[i - x] == 0 and w[i + x] != 0:
					w[i + x] = 1
				elif w[i - x] != 0 and w[i + x] == 0:
					w[i - x] = 1
				else:
					w[i - x] = 1
					w[i + x] = 1
			elif i - x >= 0 and i + x >= n:
				if w[i - x] == 0:
					flag = 1
					break
				else:
					w[i - x] = 1
			elif i - x < 0 and i + x < n:
				if w[i + x] == 0:
					flag = 1
					break
				else:
					w[i + x] = 1
			else:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		for i in range(n):
			if w[i] == -1:
				w[i] = 1
		for i in w:
			print(i, end='')
		print()


def main():
	s = input()
	n = len(s)
	x = int(input())
	t = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				t[i - x] = '0'
			if i + x < n:
				t[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			one = False
			if i - x >= 0:
				if t[i - x] == '1':
					one = True
			if i + x < n:
				if t[i + x] == '1':
					one = True
			if one == False:
				print('-1')
				return
	print(''.join(t))
for _ in range(int(input())):
	main()


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import collections as col

def solve():
	S = [int(s) for s in input()]
	X = getInt()
	N = len(S)
	ans = [-1] * N
	pairs = []
	for j in range(N):
		if S[j] == 0:
			if j - X >= 0:
				if ans[j - X] == 1:
					return -1
				ans[j - X] = 0
			if j + X < N:
				if ans[j + X] == 1:
					return -1
				ans[j + X] = 0
		elif S[j] == 1:
			if j - X >= 0 and j + X < N:
				pairs.append((j - X, j + X))
			elif j - X >= 0:
				if ans[j - X] == 0:
					return -1
				ans[j - X] = 1
			elif j + X < N:
				if ans[j + X] == 0:
					return -1
				ans[j + X] = 1
			else:
				return -1
	for (a, b) in pairs:
		if ans[a] == 0 and ans[b] == 0:
			return -1
		elif ans[a] == 0:
			ans[b] = 1
		elif ans[b] == 0:
			ans[a] = 1
		else:
			ans[a] = 1
			ans[b] = 1
	for i in range(N):
		if ans[i] == -1:
			ans[i] = 1
	return ''.join(map(str, ans))
	ans = map(str, ans)
	return ''.join(ans)
T = getInt()
for t in range(T):
	print(solve())


def solve():
	s = input()
	x = int(input())
	n = len(s)
	res = ['1'] * n
	for j in range(n):
		if s[j] == '0':
			if j - x > -1:
				res[j - x] = '0'
			if j + x < n:
				res[j + x] = '0'
	for j in range(n):
		if s[j] == '1':
			if j - x > -1 and res[j - x] == '1':
				continue
			if j + x < n and res[j + x] == '1':
				continue
			print('-1')
			return
	print(''.join(res))
t = int(input())
for i in range(t):
	solve()


def solveCase():
	res = input()
	n = len(res)
	prev = ['0' for i in range(n)]
	x = int(input())
	for i in range(n):
		if res[i] == '0':
			continue
		ok = False
		if i >= 2 * x and res[i - 2 * x] == '1' or (i >= x and i < 2 * x):
			prev[i - x] = '1'
			ok = True
		if i + 2 * x < n and res[i + 2 * x] == '1' or (i + x < n and i + 2 * x >= n):
			prev[i + x] = '1'
			ok = True
		if not ok:
			print(-1)
			return
	astr = ''
	print(astr.join(prev))
t = int(input())
for i in range(t):
	solveCase()


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x <= len(s) - 1:
				ans[i + x] = '0'
	for i in range(len(s)):
		check = '0'
		if i - x >= 0 and ans[i - x] == '1':
			check = '1'
		if i + x < len(s) and ans[i + x] == '1':
			check = '1'
		if check != s[i]:
			ans = '-1'
			break
	for i in ans:
		print(i, end='')
	print()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	s = list(sys.stdin.readline().strip())
	x = int(sys.stdin.readline())
	n = len(s)
	w = ['1'] * n
	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'
	is_there = 1
	for i in range(n):
		if s[i] == '1':
			if (i - x < 0 or w[i - x] == '0') and (i + x >= n or w[i + x] == '0'):
				is_there = 0
				break
	if is_there:
		print(''.join(w))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = str(input())
	x = int(input())
	n = len(s)
	w = [-1] * n
	for i in range(n):
		j = i - x
		k = i + x
		if 0 <= j < n and 0 <= k < n:
			if s[i] == '0':
				w[j] = '0'
				w[k] = '0'
		elif 0 <= j < n:
			if s[i] == '1':
				w[j] = '1'
			else:
				w[j] = '0'
		elif 0 <= k < n:
			if s[i] == '1':
				w[k] = '1'
			else:
				w[k] = '0'
	for i in range(n):
		if w[i] == -1:
			w[i] = '1'
	t = [-1] * n
	for i in range(n):
		j = i - x
		k = i + x
		if 0 <= j < n and 0 <= k < n:
			if w[j] == '1':
				t[i] = '1'
			elif w[k] == '1':
				t[i] = '1'
			else:
				t[i] = '0'
		elif 0 <= j < n:
			if w[j] == '1':
				t[i] = '1'
			else:
				t[i] = '0'
		elif 0 <= k < n:
			if w[k] == '1':
				t[i] = '1'
			else:
				t[i] = '0'
		else:
			t[i] = '0'
	t = ''.join(t)
	if s == t:
		print(''.join(w))
	else:
		print(-1)


for _ in range(int(input())):
	str = input()
	x = int(input())
	n = len(str)
	ans = ['1'] * n
	for i in range(n):
		if str[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	cnd = True
	for i in range(n):
		one = False
		one = one or (i - x >= 0 and ans[i - x] == '1')
		one = one or (i + x < n and ans[i + x] == '1')
		if str[i] != ('1' if one else '0'):
			print(-1)
			cnd = False
			break
	if cnd:
		for i in ans:
			print(i, end='')
		print('\n', end='')


T = int(input())
for _ in range(T):
	s = input()
	x = int(input())
	n = len(s)
	w = [-1 for i in range(n)]
	flag = 0
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				if w[i - x] == 1:
					flag = 1
					break
				else:
					w[i - x] = 0
			if i + x < n:
				if w[i + x] == 1:
					flag = 1
					break
				else:
					w[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and i + x >= n:
				if w[i - x] == 0:
					flag = 1
					break
			elif i + x < n and i - x < 0:
				if w[i + x] == 0:
					flag = 1
					break
			elif i + x >= n and i - x < 0:
				flag = 1
			elif w[i + x] == 0 and w[i - x] == 0:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		ans = ''
		for i in w:
			if i == -1:
				ans = ans + '1'
			else:
				ans = ans + '0'
		print(ans)


for _ in range(int(input())):
	s = input()
	n = int(input())
	y = len(s)
	l = [1] * y
	f = 0
	for i in range(y):
		if s[i] == '0':
			if i + n < y:
				l[i + n] = 0
			if i - n >= 0:
				l[i - n] = 0
	x = 0
	for i in range(y):
		f = 0
		if i - n >= 0 and l[i - n] == 1:
			f += 1
		if i + n < y and l[i + n] == 1:
			f += 1
		if f == 0 and s[i] == '1' or (f > 1 and s[i] == '0'):
			print('-1')
			x = 1
			break
	if x == 0:
		for j in l:
			print(j, end='')
		print()


def solve():
	s = input()
	x = int(input())
	ans = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			t = 0
			if i + x < len(s):
				ans[i + x] = 0
			if i - x >= 0:
				ans[i - x] = 0
	for i in range(len(s)):
		if s[i] == '1':
			t = 0
			if i + x < len(s):
				if ans[i + x] == 1:
					t += 1
			if i - x >= 0:
				if ans[i - x] == 1:
					t += 1
			if t == 0:
				print(-1)
				return
		if s[i] == '0':
			t = 0
			if i + x < len(s):
				if ans[i + x] == 1:
					t += 1
			if i - x >= 0:
				if ans[i - x] == 1:
					t += 1
			if t > 0:
				print(-1)
				return
	for i in range(len(ans)):
		print(ans[i], end='')
	print()

def main():
	for i in range(int(input())):
		solve()
main()


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
	s = list(map(lambda x: int(x), list(input())))
	x = int(input())
	n = len(s)
	ans = [1 for i in range(n)]
	for i in range(n):
		if s[i] == 0:
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	for i in range(n):
		if s[i] == 1:
			if (i - x < 0 or ans[i - x] == 0) and (i + x >= n or ans[i + x] == 0):
				ans = [-1]
				break
	print(''.join([str(i) for i in ans]))


t = int(input())
for case in range(t):
	s = list(map(int, list(input())))
	x = int(input())
	n = len(s)
	w = [1] * n
	for i in range(n):
		if s[i] == 0:
			if i + 1 > x:
				w[i - x] = 0
			if i + 1 + x <= n:
				w[i + x] = 0
	newS = [0] * n
	for i in range(n):
		if i + 1 > x and w[i - x] == 1:
			newS[i] = 1
		if i + 1 + x <= n and w[i + x] == 1:
			newS[i] = 1
	equal = True
	for i in range(n):
		if newS[i] != s[i]:
			equal = False
			break
	if equal:
		print(''.join(map(str, w)))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	lst = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if 0 <= i - x < n:
				lst[i - x] = '0'
			if 0 <= i + x < n:
				lst[i + x] = '0'
	ans = True
	for i in range(n):
		if s[i] == '1':
			temp = False
			if 0 <= i - x < n:
				if lst[i - x] == '1':
					temp = True
			if 0 <= i + x < n:
				if lst[i + x] == '1':
					temp = True
			if not temp:
				ans = False
				break
	if ans:
		print(''.join(lst))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	l = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				l[i + x] = 0
			if i - x >= 0:
				l[i - x] = 0
	ans = [0] * len(s)
	for i in range(len(s)):
		if l[i] == 1:
			flag = 0
			if i + x < len(l):
				ans[i + x] = 1
			if i - x >= 0:
				ans[i - x] = 1
	s = list(map(int, s))
	if ans == s:
		print(*l, sep='')
	else:
		print(-1)


for t in range(int(input())):
	s = input()
	n = len(s)
	x = int(input())
	j = 0
	ans = ['1' for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	res = True
	for i in range(n):
		if s[i] == '1':
			val = '0'
			if i - x >= 0 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
				continue
			else:
				res = False
				break
	if res == True:
		print(''.join(ans))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1' for _ in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	check = True
	for i in range(n):
		if i >= x and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			if s[i] != '1':
				check = False
				break
		elif s[i] != '0':
			check = False
			break
	if check:
		for i in w:
			print(i, end='')
		print()
	else:
		print(-1)


for t in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			wi = '0'
			if i >= x and w[i - x] == '1':
				wi = '1'
			if i + x < n and w[i + x] == '1':
				wi = '1'
			if wi != '1':
				w = ['-1']
				break
	print(''.join(w))


for _ in range(int(input())):
	s = str(input())
	x = int(input())
	l = [-1] * len(s)
	n = len(s)
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				l[i + x] = '0'
			if i - x >= 0:
				l[i - x] = '0'
	for i in range(n):
		if l[i] == -1:
			l[i] = '1'
	t = 1
	for i in range(n):
		c = 0
		if s[i] == '1':
			if i + x < n:
				if l[i + x] != '0':
					c += 1
			if i - x >= 0:
				if l[i - x] != '0':
					c += 1
			if c == 0:
				t = 0
				break
	if t:
		print(''.join(l))
	else:
		print(-1)


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	s = [int(char) for char in sys.stdin.readline().replace('\n', '')]
	x = int(sys.stdin.readline())
	w = [1] * len(s)
	n = len(s)
	for i in range(len(s)):
		if s[i] == 0 and i >= x:
			w[i - x] = 0
		if s[i] == 0 and i + x < n:
			w[i + x] = 0
	valid = True
	for i in range(n):
		if s[i] == 1 and (not (i + x < n and int(w[i + x]) == 1 or (i >= x and int(w[i - x]) == 1))):
			valid = False
			break
	if valid:
		for i in range(len(s)):
			print(w[i], end='')
		print()
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	r = True
	for i in range(n):
		if s[i] == '1':
			if i + x < n and ans[i + x] == '1' or (i - x >= 0 and ans[i - x] == '1'):
				continue
			else:
				r = False
				break
		else:
			if i + x < n:
				if ans[i + x] == '1':
					r = False
					break
			if i - x >= 0:
				if ans[i - x] == '1':
					r = False
					break
	if not r:
		print(-1)
	else:
		res = ''
		for i in ans:
			res += i
		print(res)


t = int(input())
for _ in range(t):
	a = list(input())
	x = int(input())
	ans = ['no' for i in range(len(a))]
	n = len(a)
	flag = 0
	for i in range(n):
		if a[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
		if i - x < 0 and i + x >= n:
			if a[i] == '1':
				flag = 1
				break
	if flag == 1:
		print(-1)
		continue
	for i in range(n):
		if a[i] == '1':
			if i - x >= 0 and i + x < n:
				if ans[i - x] == '0' and ans[i + x] == '0':
					flag = 1
					break
			elif i - x >= 0:
				if ans[i - x] == '0':
					flag = 1
					break
			elif i + x < n:
				if ans[i + x] == '0':
					flag = 1
					break
	if flag == 1:
		print(-1)
	else:
		for i in ans:
			if i == 'no':
				print('1', end='')
			else:
				print(i, end='')
		print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s) - 1
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i - x > -1:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	check = ['0'] * n
	for i in range(n):
		if i - x > -1 and ans[i - x] == '1' or (i + x < n and ans[i + x] == '1'):
			check[i] = '1'
	ans = ''.join(ans)
	print(ans if s[:n] == ''.join(check) else -1)


t = int(input())
while t:
	t -= 1
	f = 0
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	n = len(s)
	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'
	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')):
				f = 1
				break
	if f == 1:
		print(-1)
	else:
		print(''.join(w))


t = int(input())
for h in range(t):
	s = input()
	x = int(input())
	w = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x > -1:
				w[i - x] = '0'
			if i + x < len(s):
				w[i + x] = '0'
	for i in range(len(s)):
		if s[i] == '1':
			c = 0
			if i - x > -1 and w[i - x] != '0':
				c += 1
			if i + x < len(s) and w[i + x] != '0':
				c += 1
			if c == 0:
				w = ['-1']
				break
	print(''.join(w))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	s = input().strip()
	(x,) = I()
	n = len(s)
	w = ['1'] * len(s)
	pos = 1
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i <= n - x - 1:
				w[i + x] = '0'
	con = ''
	for i in range(n):
		st = 0
		if i >= x:
			st += int(w[i - x])
		if i <= n - x - 1:
			st += int(w[i + x])
		con += '1' if st else '0'
	if con != s:
		pos = 0
	if pos:
		print(''.join(w))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	s1 = [-1 for i in range(len(s))]
	n = len(s)
	flag = 0
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0 and i + x <= n - 1:
				if s1[i - x] == 0 or s1[i - x] == -1:
					s1[i - x] = 0
				else:
					flag = 1
					break
				if s1[i + x] == 0 or s1[i + x] == -1:
					s1[i + x] = 0
				else:
					flag = 1
					break
				continue
			if i - x < 0 and i + x > n - 1:
				if s1[i] == -1 or s1[i] == 0:
					s1[i] = 0
				else:
					flag = 1
					break
				continue
			if i - x < 0:
				if s1[i + x] == -1 or s1[i + x] == 0:
					s1[i + x] = 0
				else:
					flag = 1
					break
				continue
			elif s1[i - x] == -1 or s1[i - x] == 0:
				s1[i - x] = 0
			else:
				flag = 1
				break
		if s[i] == '1':
			if i - x < 0 and i + x > n - 1:
				flag = 1
				break
			if i - x >= 0 and i + x <= n - 1:
				if s1[i - x] == 0:
					s1[i + x] = 1
				else:
					s1[i - x] = 1
				continue
			if i - x < 0:
				if s1[i + x] == -1 or s1[i + x] == 1:
					s1[i + x] = 1
				else:
					flag = 1
					break
				continue
			if i + x > n - 1:
				if s1[i - x] == -1 or s1[i - x] == 1:
					s1[i - x] = 1
				else:
					flag = 1
					break
	if flag == 1:
		print(-1)
		continue
	for i in range(len(s1)):
		if s1[i] == -1:
			s1[i] = 1
	s3 = ''
	for i in range(len(s1)):
		s3 += str(s1[i])
	print(s3)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	s = input().strip()
	x = int(input())
	w = ['1'] * len(s)
	for (idx, ch) in enumerate(s):
		if ch == '0':
			if idx - x >= 0:
				w[idx - x] = '0'
			if idx + x <= len(s) - 1:
				w[idx + x] = '0'
	w = ''.join(w)
	for (idx, ch) in enumerate(s):
		if ch == '1':
			if idx - x < 0 and idx + x > len(s) - 1:
				print(-1)
				break
			if idx - x >= 0 and idx + x > len(s) - 1 and (w[idx - x] != '1'):
				print(-1)
				break
			if idx + x < len(s) and idx - x < 0 and (w[idx + x] != '1'):
				print(-1)
				break
			if (idx + x < len(s) and w[idx + x] != '1') and (idx - x >= 0 and w[idx - x] != '1'):
				print(-1)
				break
	else:
		print(w)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	s = input()
	x = int(input())
	(n, f) = (len(s), 0)
	z = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				z[i - x] = 0
			if i + x < n:
				z[i + x] = 0
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and z[i - x] == 1 or (i + x < n and z[i + x] == 1):
				continue
			else:
				f = 1
				break
	if f == 1:
		print(-1)
		continue
	z = map(str, z)
	print(''.join(z))


class Conflict(Exception):
	pass

def controller(s, x):
	n = len(s)
	s = tuple((i == '1' for i in s))
	w = [None] * n
	constraints = []

	def set(idx, val):
		oldval = w[idx]
		if oldval is None:
			w[idx] = val
		elif oldval is val:
			pass
		else:
			raise Conflict()
	try:
		for (i, si) in enumerate(s):
			a = i - x
			b = i + x
			has_a = 0 <= a
			has_b = b < n
			if has_a:
				if has_b:
					if si:
						constraints.append(i)
					else:
						set(a, False)
						set(b, False)
				else:
					set(a, si)
			elif has_b:
				set(b, si)
			elif si:
				raise Conflict()
		for i in constraints:
			a = w[i - x]
			b = w[i + x]
			if a or b:
				pass
			elif a is False and b is False:
				raise Conflict()
	except Conflict:
		return -1
	return ''.join(('0' if i is False else '1' for i in w))

def c_in():
	import sys, os
	file = sys.stdin
	n_test_case = int(file.readline())
	for i in range(n_test_case):
		s = file.readline().rstrip()
		x = int(file.readline())
		print(controller(s, x))
c_in()


T = int(input())
for t in range(T):
	s = input()
	x = int(input())
	n = len(s)
	w = ['1'] * n
	flag = 0
	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'
	for i in range(n):
		if s[i] == '1':
			if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
				continue
			else:
				print(-1)
				flag = 1
				break
		elif i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			print(-1)
			flag = 1
			break
	if flag:
		continue
	for i in range(n):
		print(w[i], end='')
	print()


for t in range(int(input())):
	s = input()
	x = int(input())
	a = []
	count = 0
	for i in s:
		a.append(int(i))
		count += 1
	b = [1] * count
	for i in range(count):
		if a[i] == 0:
			if i - x >= 0:
				b[i - x] = 0
			if i + x < count:
				b[i + x] = 0
	flag = 0
	for i in range(count):
		if i >= x and b[i - x] == 1 or (i + x < count and b[i + x] == 1):
			if a[i] == 0:
				flag = -1
				break
		elif a[i] == 1:
			flag = -1
			break
	if flag == -1:
		print(-1)
		continue
	for i in b:
		print(i, end='')
	print()


from math import *
for __ in range(int(input())):
	s = input()
	x = int(input())
	ans = ['1'] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ans[i - x] = '0'
			if i + x < len(s):
				ans[i + x] = '0'
	pos = True
	for i in range(len(s)):
		if s[i] == '1':
			if i - x >= 0 and i + x < len(s):
				if ans[i - x] == '0' and ans[i + x] == '0':
					pos = False
			elif i - x >= 0:
				if ans[i - x] == '0':
					pos = False
			elif i + x < len(s):
				if ans[i + x] == '0':
					pos = False
			else:
				pos = False
	if pos:
		print(''.join(ans))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	dp = [1 for i in range(n)]
	for i in range(n):
		if s[i] == '0':
			if i - x >= 0:
				dp[i - x] = 0
			if i + x < n:
				dp[i + x] = 0
	w = ''
	for i in range(n):
		b = '0'
		if i >= x and dp[i - x] == 1:
			b = '1'
		if i < n - x and dp[i + x] == 1:
			b = '1'
		w += b
	if w != s:
		print(-1)
	else:
		ans = ''
		for i in dp:
			ans += str(i)
		print(ans)


tc = int(input())
for t in range(tc):
	inp = [int(i) for i in input()]
	n = len(inp)
	x = int(input())
	res = [1] * n
	ans = 0
	for i in range(n):
		if inp[i] == 0:
			if i - x >= 0:
				res[i - x] = 0
			if i + x < n:
				res[i + x] = 0
	for i in range(n):
		if inp[i] == 1:
			f1 = False
			if i - x >= 0:
				if res[i - x] == 1:
					f1 = True
			f2 = False
			if i + x < n:
				if res[i + x] == 1:
					f2 = True
			if f1 or f2:
				continue
			else:
				ans = -1
				break
	if ans == 0:
		ans = ''
		for i in res:
			ans += str(i)
	print(ans)


t = int(input())
for _ in range(t):
	s = [int(c) for c in input()]
	n = len(s)
	x = int(input())
	w = [None] * n
	bad = False
	for i in range(0, x):
		if i + x >= n:
			if s[i] != 0:
				print(-1)
				bad = True
				break
		else:
			w[i + x] = s[i]
	if bad:
		continue
	for i in range(n - x, n):
		if i - x < 0:
			if s[i] != 0:
				print(-1)
				bad = True
				break
		else:
			if w[i - x] is not None and w[i - x] != s[i]:
				print(-1)
				bad = True
				break
			w[i - x] = s[i]
	if bad:
		continue
	for i in range(x, n - x):
		if s[i] == 0:
			if w[i - x] == 1 or w[i + x] == 1:
				print(-1)
				bad = True
				break
			w[i - x] = 0
			w[i + x] = 0
	if bad:
		continue
	for i in range(x, n - x):
		if s[i] == 1:
			if w[i - x] == 0 and w[i + x] == 0:
				print(-1)
				bad = True
				break
			if w[i - x] is None:
				w[i - x] = 1
			if w[i + x] is None:
				w[i + x] = 1
	if bad:
		continue
	print(''.join((str(int(bool(c))) for c in w)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = [int(item) for item in input().rstrip()]
	x = int(input())
	n = len(s)
	ret1 = [-1] * n
	for i in range(x, n):
		if not s[i]:
			ret1[i - x] = 0
	for i in range(n - x):
		if not s[i]:
			ret1[i + x] = 0
	for i in range(n):
		if ret1[i] == -1:
			ret1[i] = 1
	ret2 = [-1] * n
	for i in range(n):
		if i - x < 0:
			l = 0
		else:
			l = ret1[i - x]
		if i + x > n - 1:
			r = 0
		else:
			r = ret1[i + x]
		ret2[i] = l or r
	if ret2 != s:
		print(-1)
	else:
		print(''.join([str(item) for item in ret1]))


t = int(input())
for _ in range(t):
	s = list(input())
	x = int(input())
	n = len(s)
	bad = 0
	ans = [-1 for i in range(n)]
	for i in range(n):
		if i >= x and i + x < n:
			if s[i - x] == s[i + x] == '1':
				ans[i] = 1
			elif s[i - x] == s[i + x] == '0':
				ans[i] = 0
			else:
				ans[i] = 0
		elif i >= x:
			if s[i - x] == '1':
				ans[i] = 1
			elif s[i - x] == '0':
				ans[i] = 0
		elif i + x < n:
			if s[i + x] == '1':
				ans[i] = 1
			elif s[i + x] == '0':
				ans[i] = 0
		else:
			ans[i] = 0
	bad = 0
	for i in range(n):
		chr = 0
		if i >= x:
			chr = max(chr, ans[i - x])
		if i + x < n:
			chr = max(chr, ans[i + x])
		if chr != int(s[i]):
			print(-1)
			bad = 1
			break
	if not bad:
		print(''.join([str(i) for i in ans]))


for _ in range(int(input())):
	ar = input().rstrip()
	x = int(input())
	n = len(ar)
	ans = [1] * n
	for j in range(n):
		if ar[j] == '0':
			if j - x >= 0:
				ans[j - x] = 0
			if j + x < n:
				ans[j + x] = 0
	mk = ['0'] * n
	for i in range(n):
		if ans[i] == 1:
			if i - x >= 0:
				mk[i - x] = '1'
			if i + x < n:
				mk[i + x] = '1'
	mk = ''.join(mk)
	if mk == ar:
		for i in ans:
			print(i, end='')
		print()
	else:
		print('-1')


t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	w = [1] * len(s)
	for i in range(len(s)):
		if s[i] == '0':
			if i + x < len(s):
				w[i + x] = 0
			if i - x >= 0:
				w[i - x] = 0
	temp = [0] * len(s)
	for i in range(len(w)):
		f1 = 0
		f2 = 0
		if i + x < len(s):
			if w[i + x] == 1:
				f1 = 1
		if i - x >= 0:
			if w[i - x] == 1:
				f2 = 1
		if f1 or f2:
			temp[i] = 1
	ans = ''
	for i in range(len(temp)):
		ans += str(temp[i])
	if ans == s:
		e = ''
		for i in range(len(w)):
			e += str(w[i])
		print(e)
	else:
		print(-1)


for i in range(int(input())):
	s = list(str(input()))
	x = int(input())
	ss = '1' * len(s)
	s = list(s)
	ss = list(ss)
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0 and i - x < len(s):
				ss[i - x] = '0'
			if i + x <= len(s) - 1 and i + x >= 0:
				ss[i + x] = '0'
	ansc = '0' * len(ss)
	ansc = list(ansc)
	for i in range(len(ss)):
		if ss[i] == '1':
			if i - x >= 0 and i - x < len(s):
				ansc[i - x] = '1'
			if i + x < len(s) and i + x >= 0:
				ansc[i + x] = '1'
	ansc = ''.join(ansc)
	s = ''.join(s)
	if ansc == s:
		an = ''.join(ss)
		print(an)
	else:
		print(-1)


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
from math import *
for _ in range(int(input())):
	b = list(input())
	x = int(input())
	n = len(b)
	s = [int(x) for x in b]
	a = [1] * n
	for i in range(n):
		if s[i] == 0:
			if i - x >= 0:
				a[i - x] = 0
			if i + x < n:
				a[i + x] = 0
	f = 1
	for i in range(n):
		check = 0
		check = check or (i - x >= 0 and a[i - x] == 1)
		check = check or (i + x < n and a[i + x] == 1)
		if check == 0:
			if s[i] == 1:
				f = 0
				print(-1)
				break
	if f:
		print(*a, sep='')


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	s = si()
	n = len(s)
	x = fi()
	ans = [2 for i in range(n)]
	flag = 0
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				if ans[i + x] == 1:
					flag = 1
					break
				else:
					ans[i + x] = 0
			if i - x >= 0:
				if ans[i - x] == 1:
					flag = 1
					break
				else:
					ans[i - x] = 0
		else:
			c = 0
			valid = 0
			if i + x < n:
				if ans[i + x] == 0:
					c += 1
				valid += 1
			if i - x >= 0:
				if ans[i - x] == 0:
					c += 1
				valid += 1
			if c == valid:
				flag = 1
				break
			if valid == 1:
				if i - x >= 0:
					ans[i - x] = 1
				elif i + x < n:
					ans[i + x] = 1
			elif valid == 2 and c == 1:
				if ans[i - x]:
					ans[i - x] = 1
				else:
					ans[i + x] = 1
	for i in range(n):
		if ans[i] == 2:
			ans[i] = 1
		ans[i] = str(ans[i])
	print(''.join(ans) if flag == 0 else -1)


t = int(input())
for hh in range(0, t):
	s = input()
	s = list(s)
	x = int(input())
	n = len(s)
	inc = [0] * n
	ans = ['0'] * n
	for i in range(0, n):
		prev = i - x
		nxt = i + x
		if prev >= 0 and nxt < n:
			if s[prev] == '1' and s[nxt] == '1':
				ans[i] = '1'
		elif prev >= 0:
			if s[prev] == '1':
				ans[i] = '1'
		elif nxt < n:
			if s[nxt] == '1':
				ans[i] = '1'
	ans2 = ['0'] * n
	for i in range(0, n):
		if ans[i] == '1':
			prev = i - x
			nxt = i + x
			if prev >= 0:
				ans2[prev] = '1'
			if nxt < n:
				ans2[nxt] = '1'
	if s == ans2:
		print(''.join(ans))
	else:
		print(-1)


t = int(input())
output = []
for i in range(t):
	s = input()
	x = int(input())
	w = [-1] * len(s)
	ans = 0
	string = ''
	for i in range(len(s)):
		if s[i] == '0' and i + x < len(s):
			w[i + x] = 0
		if s[i] == '0' and i - x >= 0:
			w[i - x] = 0
	for i in range(len(s)):
		if s[i] == '1' and i + x < len(s) and (i - x >= 0) and (w[i - x] == -1 and w[i + x] == -1):
			w[i - x] = 1
			w[i + x] = 1
		elif s[i] == '1' and i + x < len(s) and (i - x >= 0) and (w[i - x] == -1 and w[i + x] == 0):
			w[i - x] = 1
		elif s[i] == '1' and i + x < len(s) and (i - x >= 0) and (w[i - x] == 0 and w[i + x] == -1):
			w[i + x] = 1
		elif s[i] == '1' and i + x < len(s) and (i - x >= 0) and (w[i - x] == 0 and w[i + x] == 0):
			ans = -1
		elif s[i] == '1' and i + x < len(s) and (i - x < 0) and (w[i + x] == -1):
			w[i + x] = 1
		elif s[i] == '1' and i + x < len(s) and (i - x < 0) and (w[i + x] == 0):
			ans = -1
		elif s[i] == '1' and i + x >= len(s) and (i - x >= 0) and (w[i - x] == -1):
			w[i - x] = 1
		elif s[i] == '1' and i + x >= len(s) and (i - x >= 0) and (w[i - x] == 0):
			ans = -1
		elif s[i] == '1' and i + x >= len(s) and (i - x < 0):
			ans = -1
	if ans == 0:
		for i in range(len(s)):
			if w[i] == -1:
				w[i] = 0
		string = ''.join([str(elem) for elem in w])
	else:
		string = '-1'
	output.append(string)
for i in range(t):
	print(output[i])


t = int(input())

def sxw(x, w):
	s = ['1' for i in range(len(w))]
	for i in range(len(s)):
		if i - x >= 0 and w[i - x] == '1' or (i + x < len(w) and w[i + x] == '1'):
			s[i] = '1'
		else:
			s[i] = '0'
	return s
while t != 0:
	t -= 1
	s = list(input())
	x = int(input())
	ns = list('1' * len(s))
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ns[i - x] = '0'
			if i + x < len(s):
				ns[i + x] = '0'
	if sxw(x, ns) == s:
		print(''.join(ns))
	else:
		print(-1)


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	ans = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i + x < n:
				ans[i + x] = '0'
			if i - x >= 0:
				ans[i - x] = '0'
	flag = False
	for i in range(n):
		if s[i] == '1':
			flag = True
			if i + x < n:
				if ans[i + x] == '1':
					flag = False
			if i - x >= 0:
				if ans[i - x] == '1':
					flag = False
			if flag:
				break
	if flag:
		print(-1)
	else:
		print(''.join(ans))


t = int(input())
for ii in range(t):
	s = input()
	x = int(input())
	ans = [-1] * len(s)
	can = True
	for i in range(len(s)):
		back = i - x
		front = i + x
		sor = False
		if s[i] == '1':
			if back >= 0:
				if ans[back] == -1 or ans[back] == 1:
					ans[back] = 1
					sor = True
			if not sor:
				if front < len(ans):
					if ans[front] == -1 or ans[front] == 1:
						ans[front] = 1
						sor = True
			if not sor:
				can = False
				break
		else:
			if back >= 0:
				if ans[back] == 1:
					can = False
					break
				ans[back] = 0
			if front < len(ans):
				if ans[front] == 1:
					can = False
					break
				ans[front] = 0
	if not can:
		print(-1)
	else:
		for i in range(len(ans)):
			if ans[i] == -1:
				ans[i] = 1
			print(ans[i], end='')
		print()


import sys
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
tt = int(input())
for tc in range(tt):
	s = input().strip()
	n = len(s)
	(x,) = I()
	ans = list('1' * len(s))
	for i in range(len(s)):
		if s[i] == '0':
			le = i - x
			re = i + x
			if le >= 0:
				ans[le] = '0'
			if re < len(s):
				ans[re] = '0'
	con = list('0' * len(s))
	for i in range(len(s)):
		tf = 0
		le = i - x
		re = i + x
		if le >= 0:
			if ans[le] == '1':
				tf = 1
		if re < n:
			if ans[re] == '1':
				tf = 1
		if tf:
			con[i] = '1'
	if ''.join(con) == s:
		print(''.join(ans))
	else:
		print(-1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()
from random import randint
from collections import defaultdict, deque

class Graph(object):

	def __init__(self, dic):
		self.dict = dic
		self.vertex = set()

	def addedge(self, a, b):
		if self.dict[a] == []:
			self.vertex.add(a)
		if b != None:
			self.dict[a].append(b)

	def con_com_util(self, i, unvisited, count, comp):
		for j in self.dict[i]:
			if j in unvisited:
				unvisited.remove(j)
				comp[count].append(j)
				comp = self.con_com_util(j, unvisited, count, comp)
		return comp

	def conn_components(self):
		unvisited = self.vertex.copy()
		count = 0
		comp = defaultdict(list)
		while unvisited:
			i = unvisited.pop()
			comp[count].append(i)
			comp = self.con_com_util(i, unvisited, count, comp)
			count += 1
		return (count, comp)

def countSetBits(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count
import random

def primesbelow(N):
	correction = N % 6 > 1
	N = {0: N, 1: N - 1, 2: N + 4, 3: N + 3, 4: N + 2, 5: N + 1}[N % 6]
	sieve = [True] * (N // 3)
	sieve[0] = False
	for i in range(int(N ** 0.5) // 3 + 1):
		if sieve[i]:
			k = 3 * i + 1 | 1
			sieve[k * k // 3::2 * k] = [False] * ((N // 6 - k * k // 6 - 1) // k + 1)
			sieve[(k * k + 4 * k - 2 * k * (i % 2)) // 3::2 * k] = [False] * ((N // 6 - (k * k + 4 * k - 2 * k * (i % 2)) // 6 - 1) // k + 1)
	return [2, 3] + [3 * i + 1 | 1 for i in range(1, N // 3 - correction) if sieve[i]]

def isvalid(i, n):
	if i < 0 or i >= n:
		return False
	return True

def solve():
	s = inp()
	x = int(inp())
	n = len(s)
	ar = [1] * n
	for i in range(n):
		k = int(s[i])
		if isvalid(i + x, n):
			ar[i + x] = ar[i + x] & k
		if isvalid(i - x, n):
			ar[i - x] = ar[i - x] & k
	t = 1
	d = defaultdict(int)
	for i in range(n):
		d[i] = ar[i]
	for i in range(n):
		k = int(s[i])
		if k != (d[i + x] or d[i - x]):
			t = -1
			break
	if t == -1:
		print(-1)
	else:
		ans = ''
		for i in ar:
			ans += str(i)
		print(ans)
testcase(int(inp()))


import math
t = int(input())
for _ in range(t):
	s = str(input())
	x = int(input())
	a = '0' * x + '1' * len(s) + '0' * x
	a = list(a)
	l = 0
	r = 2 * x
	for i in range(len(s)):
		if s[i] == '0':
			a[l] = 0
			a[r] = 0
		l += 1
		r += 1
	l = 0
	r = 2 * x
	for i in range(len(s)):
		if s[i] == '1':
			if a[l] == '1' or a[r] == '1':
				pass
			else:
				print(-1)
				break
		l += 1
		r += 1
	else:
		for i in range(x, x + len(s)):
			print(a[i] if a[i] != '#' else '1', end='')
		print()


def fun():
	s = input()
	x = int(input())
	ls = [1 for i in range(len(s))]
	for i in range(len(s)):
		if s[i] == '0':
			if i - x >= 0:
				ls[i - x] = 0
			if i + x < len(s):
				ls[i + x] = 0
	f = True
	for i in range(len(s)):
		if s[i] == '1':
			f2 = False
			if i - x >= 0 and ls[i - x] == 1:
				f2 = True
			if i + x < len(s) and ls[i + x] == 1:
				f2 = True
			if f2 == False:
				f = False
	if f == True:
		str = ''
		for i in range(len(s)):
			if ls[i] == 1:
				str += '1'
			else:
				str += '0'
		return str
	return '-1'

def solve():
	t = int(input())
	for i in range(t):
		print(fun())
solve()


def rn():
	a = int(input())
	return a

def rl():
	a = list(map(int, input().split()))
	return a
for _ in range(rn()):
	s = list(input())
	x = rn()
	n = len(s)
	a = ['2' for _ in range(n)]
	dt = []
	flag = 0
	for i in range(x):
		if i + x < n:
			a[i + x] = s[i]
		elif s[i] == '1':
			flag = 1
			break
	if flag == 0:
		for i in range(x, n - x):
			if s[i] == '1':
				dt.append([i - x, i + x])
			else:
				if a[i - x] == '1':
					flag = 1
					break
				else:
					a[i - x] = '0'
				if a[i + x] == '1':
					flag = 1
					break
				else:
					a[i + x] = '0'
	if flag == 0:
		for i in range(n - x, n):
			if i - x >= 0:
				if a[i - x] == '2':
					a[i - x] = s[i]
				elif a[i - x] != s[i]:
					flag = 1
					break
			elif s[i] == '1':
				flag = 1
				break
	for i in dt:
		if a[i[0]] == '1' or a[i[1]] == '1':
			continue
		if a[i[0]] == '2':
			a[i[0]] = '1'
		elif a[i[1]] == '2':
			a[i[1]] = '1'
		else:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		for i in a:
			if i == '2':
				print('1', end='')
			else:
				print(i, end='')
		print('')


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	st = input()
	x = get_int()
	n = len(st)
	ans = [1] * n
	for (i, v) in enumerate(st):
		if v == '0':
			if i - x >= 0:
				ans[i - x] = 0
			if i + x < n:
				ans[i + x] = 0
	for (i, v) in enumerate(st):
		if i - x >= 0:
			if ans[i - x] == 1:
				if v == '1':
					continue
				else:
					return False
		if i + x < n:
			if ans[i + x] == 1:
				if v == '1':
					continue
				else:
					return False
		if v == '1':
			return False
	return ''.join([str(e) for e in ans])

def main():
	ans = solve()
	if ans:
		print(ans)
	else:
		print('-1')
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


for t in range(int(input())):
	s = [int(c == '1') for c in input()]
	x = int(input())
	n = len(s)
	sat = lambda i: s[i] if i in range(n) else 1
	w = [sat(i - x) & sat(i + x) for i in range(n)]
	wat = lambda i: w[i] if i in range(n) else 0
	s_ref = [wat(i - x) | wat(i + x) for i in range(n)]
	if s != s_ref:
		print(-1)
	else:
		print(''.join(map(str, w)))


for _ in range(int(input())):
	s = input()
	x = int(input())
	n = len(s)
	f = 0
	v = ['1'] * n
	c = 0
	k = x
	for i in range(n):
		if s[i] == '0':
			if i - k >= 0:
				v[i - k] = '0'
			if i + k < n:
				v[i + k] = '0'
	for i in range(n):
		if s[i] == '1':
			f = 1
			if i - k >= 0:
				if v[i - k] == '1':
					f = 0
			if i + k < n:
				if v[i + k] == '1':
					f = 0
			if f:
				break
	if f:
		print('-1')
	else:
		x = ''
		for i in v:
			x += str(i)
		print(x)


t = int(input())
for i in range(t):
	s = input()
	m = len(s)
	x = int(input())
	ANS = [1] * m
	for i in range(m):
		if s[i] == '0':
			if i - x >= 0:
				ANS[i - x] = 0
			if i + x < m:
				ANS[i + x] = 0
	ng = 0
	for i in range(m):
		one = 0
		if i - x >= 0 and ANS[i - x] == 1 or (i + x < m and ANS[i + x] == 1):
			one = 1
		if one == 1 and s[i] == '0' or (one == 0 and s[i] == '1'):
			ng = 1
			break
	if ng == 1:
		print(-1)
	else:
		print(''.join([str(i) for i in ANS]))


for i in range(int(input())):
	s = input()
	x = int(input())
	w = ['x'] * len(s)
	ip = 0
	for j in range(len(s)):
		if j - x < 0 and j + x >= len(s):
			if s[j] == '1':
				ip = 1
				break
			else:
				w[j] = '0'
		elif j - x < 0:
			w[j + x] = s[j]
		elif j - x >= 0 and j + x < len(s):
			if s[j] == '0':
				if w[j - x] == '1':
					ip = 1
					break
				w[j - x] = w[j + x] = '0'
			elif w[j - x] == 'x':
				w[j - x] = '1'
			elif w[j - x] == '0':
				w[j + x] = '1'
		elif j + x >= len(s):
			if w[j - x] == 'x':
				w[j - x] = s[j]
			elif w[j - x] != s[j]:
				ip = 1
				break
	if ip:
		print(-1)
	else:
		ans = ''
		for a in w:
			if a == 'x':
				a = '1'
			ans += a
		print(ans)


t = int(input())
for a in range(t):
	s = list(input())
	x = int(input())
	n = len(s)
	w = list()
	for tt in range(n):
		w.append('1')
	for i in range(n):
		if '0' == s[i]:
			if i >= x:
				w[i - x] = '0'
			if n > i + x:
				w[i + x] = '0'

	def f(qq):
		ww = list()
		for ii in range(n):
			if ii >= x and qq[ii - x] == '1' or (n > ii + x and qq[ii + x] == '1'):
				ww.append('1')
			else:
				ww.append('0')
		return ww
	if f(w) == s:
		print(''.join(w))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	ans = [None] * n
	x = int(input())
	cek = False
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = '0'
			if i + x < n:
				ans[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			if i >= x and ans[i - x] != '0':
				ans[i - x] = '1'
				continue
			if i + x < n and ans[i + x] != '0':
				ans[i + x] = '1'
			else:
				print(-1)
				cek = True
				break
	if cek:
		continue
	for i in range(n):
		if ans[i] == None:
			ans[i] = '1'
	print(*ans, sep='')


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	x = int(input())
	before = 0 - x
	after = 0 + x
	n = len(s)
	w = [-1] * n
	Dict = defaultdict(int)
	flag = 0
	for i in range(len(s)):
		if s[i] == '1':
			if before >= 0 and (Dict[before] == 0 or w[before] == 1):
				w[before] = 1
				Dict[before] += 1
			elif after < n and (Dict[after] == 0 or w[after] == 1):
				w[after] = 1
				Dict[after] += 1
			else:
				flag = 1
				break
		else:
			if before < 0:
				temp_b = 1
			else:
				temp_b = 0
			if after >= n:
				temp_a = 1
			else:
				temp_a = 0
			if before >= 0 and (Dict[before] == 0 or w[before] == 0):
				w[before] = 0
				Dict[before] += 1
				temp_b = 1
			if after < n and (Dict[after] == 0 or w[after] == 0):
				w[after] = 0
				Dict[after] += 1
				temp_a = 1
			if temp_b == 0 or temp_a == 0:
				flag = 1
				break
		before += 1
		after += 1
	if flag == 1:
		print(-1)
	else:
		for i in range(n):
			if w[i] == -1:
				w[i] = 1
		w = [str(i) for i in w]
		print(''.join(w))


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	s = input()[:-1]
	x = int(input())
	w = ['1'] * len(s)
	for (i, c) in enumerate(s):
		pi = i + 1
		if c == '0':
			if pi > x:
				ppw = pi - x
				w[ppw - 1] = '0'
			if pi + x <= len(s):
				ppw = pi + x
				w[ppw - 1] = '0'
	for (i, c) in enumerate(s):
		pi = i + 1
		if c == '1':
			if pi > x:
				ppw = pi - x
				if w[ppw - 1] == '1':
					continue
			if pi + x <= len(s):
				ppw = pi + x
				if w[ppw - 1] == '1':
					continue
			print(-1)
			break
	else:
		print(''.join(w))


rr = lambda : input().strip()

def constu(w, n, x):
	sx = list(w)
	for i in range(n):
		if i - x >= 0 and w[i - x] == '1' or (i + x < n and w[i + x] == '1'):
			sx[i] = '1'
		else:
			sx[i] = '0'
	sx = ''.join(sx)
	return sx

def solve(s):
	x = int(rr())
	n = len(s)
	w = ['1'] * n
	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'
	te = constu(w, n, x)
	if s == te:
		w = ''.join(w)
		return w
	else:
		return -1
T = int(rr())
for _ in range(T):
	s = rr()
	ans = solve(s)
	print(ans)


t = int(input())
for i in range(t):
	s = str(input())
	x = int(input())
	cond = True
	st = 0
	en = len(s)
	ans = list(('1' for x in s))
	cond = True
	for i in range(st, en):
		if s[i] == '0':
			if i - x >= st:
				ans[i - x] = '0'
			if i + x < en:
				ans[i + x] = '0'
	for i in range(st, en):
		one = False
		one = one or (i - x >= 0 and ans[i - x] == '1')
		one = one or (i + x < en and ans[i + x] == '1')
		if one:
			one = '1'
		else:
			one = '0'
		if s[i] != one:
			cond = False
			break
	if cond:
		print(''.join(ans))
	else:
		print(-1)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		string = input()
		x = int(input())
		n = len(string)
		markpoint = []
		Failed = False
		for i in range(n):
			if string[i] == '0':
				markpoint.append(i)
		dic = {}
		for ele in markpoint:
			if ele - x >= 0:
				dic[ele - x] = True
			if ele + x <= n - 1:
				dic[ele + x] = True
		for ele in dic:
			if ele - x >= 0:
				if ele - 2 * x >= 0:
					if dic.get(ele - 2 * x, False):
						if string[ele - x] != '0':
							Failed = True
							break
					elif string[ele - x] != '1':
						Failed = True
						break
				elif string[ele - x] != '0':
					Failed = True
					break
			if ele + x <= n - 1:
				if ele + 2 * x <= n - 1:
					if dic.get(ele + 2 * x, False):
						if string[ele + x] != '0':
							Failed = True
							break
					elif string[ele + x] != '1':
						Failed = True
						break
				elif string[ele + x] != '0':
					Failed = True
					break
		if Failed:
			yield (-1)
		else:
			ans = []
			for i in range(n):
				if dic.get(i, False):
					ans.append('0')
				else:
					ans.append('1')
			kap = ''.join(ans)
			right = True
			for i in range(n):
				curr = False
				if i - x >= 0:
					if kap[i - x] == '1':
						curr = True
				if i + x <= n - 1:
					if kap[i + x] == '1':
						curr = True
				if curr:
					if string[i] != '1':
						right = False
						break
				elif string[i] != '0':
					right = False
					break
			if right:
				yield kap
			else:
				yield (-1)
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	string = input()
	string1 = []
	for i in string:
		string1.append(int(i))
	x = int(input())
	n = len(string1)
	initial = [1] * n
	for i in range(n):
		if string1[i] == 0:
			if i >= x:
				initial[i - x] = 0
			if i + x < n:
				initial[i + x] = 0
	matching = []
	for i in range(n):
		v = 0
		if i >= x and initial[i - x] == 1:
			v = 1
		if i + x < n and initial[i + x] == 1:
			v = 1
		matching.append(v)
	if matching != string1:
		print(-1)
	else:
		an = ''
		for i in range(len(initial)):
			an += str(initial[i])
		print(an)


for _ in range(int(input())):
	s = input()
	x = int(input())
	ans = ['1'] * len(s)
	c = []
	for i in range(len(s)):
		if s[i] == '0':
			if i >= x:
				ans[i - x] = '0'
			if i < len(s) - x:
				ans[i + x] = '0'
	for i in range(len(ans)):
		if i >= x and ans[i - x] == '1' or (i < len(ans) - x and ans[i + x] == '1'):
			c.append('1')
		else:
			c.append('0')
	print(''.join(ans) if s == ''.join(c) else -1)


for _ in range(int(input())):
	s = list(map(int, input()))
	st = ''
	g = ''
	a = int(input())
	p = [1] * len(s)
	q = [0] * len(s)
	for i in range(len(s)):
		if s[i] == 0:
			if i - a >= 0:
				p[i - a] = 0
			if i + a < len(s):
				p[i + a] = 0
	for i in range(len(p)):
		if p[i] == 1:
			if i - a >= 0:
				q[i - a] = 1
			if i + a < len(s):
				q[i + a] = 1
	if q != s:
		print(-1)
	else:
		print(''.join(map(str, p)))


from collections import defaultdict as dc
import sys
from collections import Counter as cnt
from collections import deque as dq
from copy import copy, deepcopy
import itertools
import math
mod = 10 ** 9 + 7

def sinp():
	p = str(sys.stdin.readline())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		for j in range(2 * i, n + 1, i):
			p[i] = 1
	return p

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def ind(a):
	return ord(a) - ord('A')

def digit(n):
	p = [int(i) for i in str(n)]
	return p

def check(p, n):
	l = str(p)
	s = ''
	for i in range(n):
		s = s + bin(int(l[i]))[2:]
	s = s[:-n]
	if s == '':
		return 0
	return int(s, 2)

def createcomb(a, n, i):
	if i == n:
		ans.append(a)
	else:
		for z in range(n):
			a.append(a[z])
			createcomb(a, n, z)
			a.pop()

def solve(a, n, a1, b1, c1):
	l = []
	r = []
	x = 0
	for i in range(n):
		if a[i] >= x:
			l.append(i)
			x = a[i]
	x = 0
	for i in range(n - 1, -1, -1):
		if a[i] >= x:
			r.append(i)
			x = a[i]
	z = cnt(r)
	c = 0
	p = len(l)
	q = len(r)
	for i in l:
		if z[i]:
			c += 1
	if p == a1 and q == b1 and (c1 == c):
		return 1
	return 0

def xor(a, b):
	s = ''
	for i in range(len(a)):
		if a[i] == '1' and b[i] == '0':
			s += '1'
		elif b[i] == '1' and a[i] == '0':
			s += '1'
		else:
			s += '0'
	return s
for t in range(inp()):
	s = str(input())
	x = inp()
	n = len(s)
	w = list('_' * n)
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
		else:
			if i >= x and w[i - x] == '_':
				w[i - x] = '1'
			if i + x < n and w[i + x] == '_':
				w[i + x] = '1'
	for i in range(n):
		if w[i] == '_':
			w[i] = '0'
	p = list('_' * n)
	for i in range(n):
		if i >= x and w[i - x] == '1':
			p[i] = '1'
		elif i + x < n and w[i + x] == '1':
			p[i] = '1'
		else:
			p[i] = '0'
	w = ''.join(w)
	p = ''.join(p)
	if p != s:
		print(-1)
	else:
		print(w)