#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f, g, n, m, k, t, x, h, w, p, q, y;
string str = "";
long long mod = 1e9 + 7;
void solve() {
  cin >> n >> k >> str;
  str = '*' + str;
  bool ok = true;
  for (int i = 1; i <= k; i++) {
    bool one = false;
    bool zero = false;
    for (int j = i; j <= n; j += k) {
      if (str[j] == '1') one = true;
      if (str[j] == '0') zero = true;
    }
    if (one && zero) ok = false;
    if (!one && !zero) continue;
    for (int j = i; j <= n; j += k) {
      if (one)
        str[j] = '1';
      else
        str[j] = '0';
    }
  }
  vector<int> dp0(n + 1, 0);
  vector<int> dp1(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    dp0[i] = dp0[i - 1] + (str[i] == '0');
    dp1[i] = dp1[i - 1] + (str[i] == '1');
  }
  for (int i = k; i <= n; i++) {
    int ones = dp1[i] - dp1[i - k];
    int zeroes = dp0[i] - dp0[i - k];
    int other = k - ones - zeroes;
    if (ones < zeroes) swap(ones, zeroes);
    if (ones > other + zeroes) ok = false;
  }
  if (!ok) {
    cout << "NO\n";
  } else
    cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int cases = 1;
  cin >> cases;
  while (cases--) solve();
  return 0;
}
