#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k;
string s;
void read_input() { cin >> n >> k >> s; }
int change_to_number(char ch) {
  if (ch == '0') return 0;
  if (ch == '1') return 1;
  return 2;
}
bool ok(int cnt0, int cnt1) { return cnt0 <= k / 2 && cnt1 <= k / 2; }
void solve() {
  vector<int> V(k, 2);
  for (int i = 0; i < n; i++) {
    if ((V[i % k] == 1 && s[i] == '0') || (V[i % k] == 0 && s[i] == '1')) {
      cout << "NO" << '\n';
      return;
    }
    V[i % k] = (V[i % k] == 2 ? change_to_number(s[i]) : V[i % k]);
  }
  for (int i = 0; i < k; i++) {
    for (int j = i; j < n; j += k) {
      s[j] = (char)(V[i % k] + '0');
    }
  }
  int cnt0 = 0, cnt1 = 0;
  for (int i = 0; i < k; i++) {
    cnt0 += (s[i] == '0'), cnt1 += (s[i] == '1');
  }
  if (!ok(cnt0, cnt1)) {
    cout << "NO" << '\n';
    return;
  }
  cout << "YES" << '\n';
}
void write_output() {}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    read_input();
    solve();
  }
  return 0;
}
