#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long one = 0, zero = 0, un = 0;
  for (long long i = 0; i < k; i++) {
    long long status = -1;
    for (long long j = i; j < n; j += k) {
      if (s[j] == '0') {
        if (status == 1) {
          cout << "NO"
               << "\n";
          return;
        } else if (status == -1 || status == 0) {
          status = 0;
        }
      } else if (s[j] == '1') {
        if (status == 0) {
          cout << "NO"
               << "\n";
          return;
        } else if (status == -1 || status == 1) {
          status = 1;
        }
      }
    }
    if (status != -1) {
      for (long long j = i; j < n; j += k) {
        s[j] = status + '0';
      }
    }
  }
  for (long long i = 0; i < k; i++) {
    if (s[i] == '1')
      one++;
    else if (s[i] == '0')
      zero++;
    else
      un++;
  }
  if (one > k / 2 || zero > k / 2) {
    cout << "NO"
         << "\n";
    return;
  }
  cout << "YES"
       << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(8);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
