#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool g = 1;
    int zs = 0, ons = 0, bls = 0;
    for (int i = 0; i < k; i++) {
      char c = '?';
      for (int x = i; x < n; x = x + k) {
        if (s[x] != '?') {
          c = s[x];
          break;
        }
      }
      if (c != '?') {
        for (int x = i; x < n; x = x + k) {
          if (s[x] == '?') {
            s[x] = c;
          } else if (s[x] != c)
            g = 0;
        }
        if (g == 0) break;
      }
    }
    if (g) {
      for (int i = 0; i < k; i++) {
        if (s[i] == '0')
          zs++;
        else if (s[i] == '1')
          ons++;
      }
      if (zs > k / 2 || ons > k / 2) g = 0;
    }
    if (g)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  return 0;
}
