#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long int mod(long long int x) { return (x % MOD + MOD) % MOD; }
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (long long int i = 0; i < k; i++) {
    if (s[i] == '?') {
      for (long long int j = i + k; j < n; j += k) {
        if (s[j] != '?') {
          s[i] = s[j];
          break;
        }
      }
    }
  }
  for (long long int i = 0; i < k; i++) {
    if (s[i] != '?') {
      for (long long int j = i + k; j < n; j += k) {
        if (s[j] == '?') {
          s[j] = s[i];
        } else if (s[i] != s[j]) {
          cout << "NO\n";
          return;
        }
      }
    }
  }
  long long int c1 = 0, c0 = 0;
  for (long long int i = 0; i < k; i++) {
    if (s[i] == '1')
      c1 += 1;
    else if (s[i] == '0')
      c0 += 1;
  }
  if (c0 > k / 2 or c1 > k / 2) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
