#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int m = 1e9 + 7;
long long int fact[5 * 100000 + 3];
long long int modularExponentiation(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % m, n / 2) % m;
  else
    return (x * (modularExponentiation((x * x) % m, n / 2)) % m) % m;
}
long long int GCD(long long int a, long long int b) {
  if (a == 0) return b;
  return GCD(b % a, a);
}
long long int ncr(long long int n, long long int r) {
  return (fact[n] * modularExponentiation(fact[n - r], m - 2) % m) *
         modularExponentiation(fact[r], m - 2) % m;
}
void solve() {
  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int dp[3] = {0};
  char c[k];
  for (int i = 0; i < k; i++) c[i] = '?';
  for (int i = 0; i < n; i++) {
    if (c[i % k] == '?') {
      c[i % k] = str[i];
    } else {
      if (c[i % k] == '1' && str[i] == '0') {
        cout << "NO" << endl;
        return;
      }
      if (c[i % k] == '0' && str[i] == '1') {
        cout << "NO" << endl;
        return;
      }
    }
  }
  int a = 0, b = 0;
  for (int i = 0; i < k; i++) {
    if (c[i] == '0')
      a++;
    else if (c[i] == '1')
      b++;
  }
  if (a > k / 2 || b > k / 2) {
    cout << "NO" << endl;
    return;
  } else
    cout << "YES" << endl;
  return;
}
int main() {
  int t = 1;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    solve();
  }
}
