#include <bits/stdc++.h>
const double pi = 4 * atan(1);
using namespace std;
const long long MOD = 1000000007;
const int MAXN = 200005;
bool is_bit(char x) { return x == '1' || x == '0'; }
bool solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    char c = '?';
    for (int j = i; j < n; j += k) {
      if (is_bit(s[j])) {
        if (c == '?') {
          c = s[j];
        } else if (c != s[j]) {
          return false;
        }
      }
    }
    for (int j = i; j < n; j += k) {
      s[j] = c;
    }
  }
  map<char, int> cnt;
  for (int i = 0; i < k; i++) {
    cnt[s[i]]++;
  }
  if (cnt['0'] <= k / 2 && cnt['1'] <= k / 2) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int __tc;
  cin >> __tc;
  for (long long case_num = (1); (case_num) < (__tc + 1); ++case_num) {
    cout << (solve() ? "YES\n" : "NO\n");
  }
}
