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
# cook your dish here
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
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
#from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+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))
