#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool bol = 1;
    for (int i = 0; i < k; i++) {
      char c = '?';
      for (int j = i; j < s.size(); j += k) {
        if (s[j] == '?') continue;
        if (c != '?' && c != s[j]) bol = 0;
        c = s[j];
      }
      for (int j = i; j < s.size(); j += k) s[j] = c;
    }
    if (!bol) {
      cout << "NO\n";
      continue;
    }
    int num0 = 0;
    int num1 = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == '0') num0++;
      if (s[i] == '1') num1++;
    }
    if (num1 <= k / 2 && num0 <= k / 2)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
