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