#include <bits/stdc++.h>
const long long INF = 2147483647;
const long long MOD = 1000000007;
const long long mod = 998244353;
const long double eps = 1e-18;
using namespace std;
char str[300001];
long long n;
long long k;
long long c0, c1, cq;
bool flag;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    cin >> n >> k >> str;
    flag = 1;
    for (long long i = 0; i < k; i++) {
      c0 = 0;
      c1 = 0;
      cq = 0;
      for (long long j = i; j < n; j += k) {
        if (str[j] == '0') {
          c0++;
        } else if (str[j] == '1') {
          c1++;
        } else {
          cq++;
        }
      }
      if (c0 > 0 and c1 > 0) {
        flag = 0;
      }
      if (c0 > 0) {
        for (long long j = i; j < n; j += k) {
          if (str[j] == '1') {
            flag = 0;
          }
          str[j] = '0';
        }
      } else if (c1 > 0) {
        for (long long j = i; j < n; j += k) {
          if (str[j] == '0') {
            flag = 0;
          }
          str[j] = '1';
        }
      }
    }
    c0 = 0;
    c1 = 0;
    cq = 0;
    for (long long i = 0; i < k; i++) {
      if (str[i] == '0') {
        c0++;
      } else if (str[i] == '1') {
        c1++;
      } else {
        cq++;
      }
    }
    if (c0 > k / 2 or c1 > k / 2) {
      flag = 0;
    }
    if (flag == 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
