#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int N = 3e5 + 5;
const int M = 1e5 + 5;
const int mod = 1e9 + 7;
int T;
char s[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    cin >> s;
    int a = 0, b = 0, c = 0;
    bool flag = true;
    for (int i = 0; i + k < n; ++i) {
      if (s[i] != s[i + k] && s[i] != '?' && s[i + k] != '?') flag = false;
      if (s[i] == '?') {
        if (s[i + k] != '?') s[i] = s[i + k];
      }
      if (s[i + k] == '?')
        if (s[i] != '?') s[i + k] = s[i];
    }
    for (int i = n - 1; i - k >= 0; --i) {
      if (s[i] != s[i - k] && s[i] != '?' && s[i - k] != '?') flag = false;
      if (s[i] == '?') {
        if (s[i - k] != '?') s[i] = s[i - k];
      }
      if (s[i - k] == '?')
        if (s[i] != '?') s[i - k] = s[i];
    }
    if (!flag)
      cout << "NO" << endl;
    else {
      for (int i = 0; i < k; ++i) {
        if (s[i] == '0')
          ++a;
        else if (s[i] == '1')
          ++b;
        else
          ++c;
      }
      int tmp = c - abs(a - b);
      if (tmp >= 0 && !(tmp & 1))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
