#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long int a = 0, b = 0, c = 0, flag = 0;
    for (long long int i = 0; i < k; i++) {
      a = 0;
      b = 0;
      c = 0;
      for (long long int j = i; j < n; j += k) {
        if (s[j] == '0') a = 1;
        if (s[j] == '1') b = 1;
        if (s[j] == '?') c = 1;
      }
      if (a + b > 1)
        flag = 1;
      else {
        if (c) s[i] = '?';
        if (a) s[i] = '0';
        if (b) s[i] = '1';
      }
    }
    a = 0;
    b = 0;
    c = 0;
    for (long long int i = 0; i < k; i++) {
      if (s[i] == '0') a++;
      if (s[i] == '1') b++;
      if (s[i] == '?') c++;
    }
    if (a > k / 2 || b > k / 2) flag = 1;
    if (flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
