#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    string s;
    cin >> n >> k >> s;
    bool can = true;
    for (int i = 0; i < k; i++) {
      vector<int> cnt(2);
      vector<int> p;
      for (int j = i; j < n; j += k) {
        if (s[j] == '?')
          p.push_back(j);
        else
          cnt[s[j] - '0']++;
      }
      if (cnt[0] && cnt[1]) {
        can = false;
        break;
      } else {
        if (cnt[0]) {
          for (auto x : p) s[x] = '0';
        }
        if (cnt[1]) {
          for (auto x : p) s[x] = '1';
        }
      }
    }
    int one = 0, zero = 0;
    for (int i = 0; i < k && can; i++) {
      if (s[i] == '1') one++;
      if (s[i] == '0') zero++;
      if (one > k / 2 || zero > k / 2) can = false;
    }
    if (can)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
