#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse2")
void opting() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
long long inp() {
  long long x;
  cin >> x;
  return x;
}
const int maxn = 1e5 + 69, delta = 1e9 + 7;
int main() {
  opting();
  int t = inp();
  while (t--) {
    int n, k;
    cin >> n >> k;
    char r[k];
    memset(r, '?', sizeof r);
    string s;
    cin >> s;
    bool pos = true;
    for (int i = 0; i < n; i++)
      if (s[i] == '?')
        continue;
      else if (s[i] != r[i % k] and r[i % k] != '?')
        pos = false;
      else
        r[i % k] = s[i];
    int O, Z;
    O = Z = 0;
    for (int i = 0; i < k; i++)
      if (r[i] == '1')
        O++;
      else if (r[i] == '0')
        Z++;
    if (!pos or O > k / 2 or Z > k / 2)
      cout << "NO";
    else
      cout << "YES";
    cout << '\n';
  }
}
