#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool ok = true;
    int op = 0, tp = 0;
    for (int i = 0; i < k; i++) {
      int one = 0, zero = 0;
      for (int j = i; j < n; j += k) {
        if (s[j] == '0') zero++;
        if (s[j] == '1') one++;
      }
      if (one > 0 && zero > 0) {
        ok = false;
        break;
      }
      if (one > 0) op++;
      if (zero > 0) tp++;
    }
    if (!ok || op > k / 2 || tp > k / 2) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
}
