#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int N = 1e6 + 7;
char s[N];
int main() {
  int Case = 0;
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    cin >> s;
    bool flag = true;
    int c0 = 0, c1 = 0;
    for (int i = k; s[i]; i++) {
      if (s[i] == '?' || s[i] == s[i % k]) continue;
      if (s[i % k] == '?')
        s[i % k] = s[i];
      else {
        flag = false;
        break;
      }
    }
    for (int i = 0; i < k; i++) {
      if (s[i] == '0')
        c0++;
      else if (s[i] == '1')
        c1++;
    }
    if (c0 > k / 2 || c1 > k / 2) flag = false;
    puts(flag ? "YES" : "NO");
  }
  return 0;
}
