#include <bits/stdc++.h>
using namespace std;
bool valid(string s, int k, int n) {
  for (int i = 0; i < k; i++) {
    int zero = 0, one = 0;
    for (int j = i; j < n; j += k) {
      one += s[j] == '1';
      zero += s[j] == '0';
    }
    if (one && zero) return 0;
    if (one)
      s[i] = '1';
    else if (zero)
      s[i] = '0';
  }
  if (count(s.begin(), s.begin() + k, '1') > k / 2 ||
      count(s.begin(), s.begin() + k, '0') > k / 2)
    return 0;
  return 1;
}
int main() {
  int t, k, n;
  string s;
  for (cin >> t; t; t--) {
    cin >> n >> k >> s;
    if (valid(s, k, n))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
