#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, cnt[2]{};
    string s;
    cin >> n >> k >> s;
    for (int i = 0; i < k; ++i) {
      int tmp = -1;
      for (int j = i; j < n; j += k) {
        if (s[j] == '0') {
          if (tmp == 1) {
            cout << "NO\n";
            goto next;
          }
          tmp = 0;
        } else if (s[j] == '1') {
          if (tmp == 0) {
            cout << "NO\n";
            goto next;
          }
          tmp = 1;
        }
      }
      if (~tmp) ++cnt[tmp];
    }
    if (max(cnt[0], cnt[1]) > k / 2)
      cout << "NO\n";
    else
      cout << "YES\n";
  next:;
  }
}
