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 java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;

/*
By : SSD
*/

public class C {
	long mod = (long) (1e9 + 7);

	static class InputReader1 {

		private final InputStream st;
		private final byte[] buf = new byte[8192];
		private int cc, sc;
		private SpaceCharFilter f;

		public InputReader1(InputStream st) {
			this.st = st;
		}

		public int t() {
			if (sc == -1)
				throw new InputMismatchException();
			if (cc >= sc) {
				cc = 0;
				try {
					sc = st.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (sc <= 0)
					return -1;
			}
			return buf[cc++];
		}

		public int nextInt() {
			int c = t();
			while (isSpaceChar(c)) {
				c = t();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = t();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = t();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = t();
			while (isSpaceChar(c)) {
				c = t();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = t();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = t();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = t();
			while (isSpaceChar(c)) {
				c = t();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = t();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = t();
			while (isSpaceChar(c))
				c = t();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = t();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (f != null)
				return f.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}
	}

	InputReader1 sc;
	OutputWriter out;

	public static void main(String[] ssd) throws Exception {
		new C().run();
	}

	void run() throws Exception {

		sc = new InputReader1(System.in);

		out = new OutputWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		tr(System.currentTimeMillis() - s + "ms");
		out.close();

	}

	boolean canGo(int index, int n) {
		if (index < n && index >= 0)
			return true;
		return false;

	}

	private void solve() {

		int tt = sc.nextInt();
		while (tt-- > 0) {

			char[] s = sc.readString().toCharArray();
			int x = sc.nextInt();
			int n = s.length;

			char ans[] = new char[n];
			for (int i = 0; i < ans.length; i++) {
				ans[i] = '1';
			}
			for (int i = 0; i < n; i++) {
				if (s[i] == '0') {
					if (canGo(i - x, n)) ans[i - x] = '0';					
					if (canGo(i + x, n)) ans[i + x] = '0';

				}
			}

			boolean isPossible = true;

			for (int i = 0; i < n; i++) {
				if (s[i] == '1') {
					if (canGo(i - x, n)) {
						if (ans[i - x] == '1') {
							continue;
						}
					}
					if (canGo(i + x, n)) {
						if (ans[i + x] == '1') {
							continue;
						}
					} 
						isPossible = false;
				
				}

			}

			if (isPossible) {
				System.out.println(ans);

			} else {
				System.out.println(-1);
			}

		}

	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			out.println(Arrays.deepToString(o));
	}
}
