#include <bits/stdc++.h>   using namespace std;   int T, x;   char str[100005], ans[100005];   char usd[100005];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %s , str + 1);       scanf( %d , &x);       int n = strlen(str + 1);       for (int i = 1; i <= n; ++i) {         if (str[i] ==  0 ) {           if (i + x <= n) ans[i + x] =  0 ;           if (i - x >= 1) ans[i - x] =  0 ;         }       }       for (int i = 1; i <= n; ++i)         if (!ans[i]) ans[i] =  1 ;       for (int i = 1; i <= n; ++i) {         if (i - x >= 1 && ans[i - x] ==  1 )           usd[i] =  1 ;         else if (i + x <= n && ans[i + x] ==  1 )           usd[i] =  1 ;         else           usd[i] =  0 ;       }       bool flag = true;       for (int i = 1; i <= n; ++i)         if (usd[i] != str[i]) {           flag = false;           break;         }       if (!flag)         printf( -1 n );       else         printf( %s n , ans + 1);       for (int i = 1; i <= n; ++i) ans[i] = 0;     }     return 0;   }   