#include <bits/stdc++.h>
using namespace std;
int n, k, sum1, sum2;
string a;
int f[300011];
void solve() {
  scanf("%d%d", &n, &k);
  cin >> a;
  memset(f, -1, sizeof(f));
  for (int i = 0; i < n; i++) {
    if (a[i] != '?') {
      if (f[i % k] == -1)
        f[i % k] = a[i] - '0';
      else if (f[i % k] != (int)(a[i] - '0')) {
        cout << "NO" << endl;
        return;
      }
    }
  }
  sum1 = sum2 = 0;
  for (int i = 0; i < k; i++) {
    sum1 += (f[i] == 0);
    sum2 += (f[i] == 1);
  }
  if (sum1 > k / 2 || sum2 > k / 2)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
