#include <bits/stdc++.h>
using namespace std;
int t;
string s;
int main() {
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    cin >> s;
    bool flag = true;
    for (int i = k; i < n; i++) {
      if (s[i] == s[i % k] || s[i] == '?') continue;
      if (s[i % k] == '?') {
        s[i % k] = s[i];
      } else {
        flag = false;
        break;
      }
    }
    int c1 = 0, c0 = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == '1')
        c1++;
      else if (s[i] == '0')
        c0++;
    }
    if (c1 > k / 2 || c0 > k / 2) {
      flag = false;
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
