#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 0, cnt2 = 0;
  vector<int> v(n, -1);
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      if (v[i % k] == 0) {
        cout << "NO\n";
        return;
      } else {
        v[i % k] = 1;
      }
    } else if (s[i] == '0') {
      if (v[i % k] == 1) {
        cout << "NO\n";
        return;
      } else {
        v[i % k] = 0;
      }
    } else {
      if (v[i % k] == 1)
        s[i] = '1';
      else if (v[i % k] == 0)
        s[i] = '0';
    }
  }
  for (int i = 0; i < k; i++) {
    if (v[i] == 1)
      cnt++;
    else if (v[i] == 0)
      cnt--;
    else
      cnt2++;
  }
  if (abs(cnt) > cnt2) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
