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 ≤ 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 ≤ t ≤ 1000) — the number of test cases.

Each test case consists of two lines. The first line contains the resulting string s (2 ≤ |s| ≤ 10^5, each character of s is either 0 or 1). The second line contains one integer x (1 ≤ x ≤ |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
import os
import sys
from io import BytesIO, IOBase


def main():
    pass


# region fastio

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
            else:
                if(((int(ans[i-k]))|(int(ans[i+k])))!=int(s[i])):
                    f=False
                    break
        else:
            if(ans[i]!=s[i]):
                f=False
                break
    if(f):
        print("".join(ans))
    else:
        print(-1)