#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    vector<set<long long int>> v(k);
    for (long long int i = 0; i < n; ++i) {
      char c;
      cin >> c;
      if (c == '?') continue;
      if (c == '1')
        v[i % k].insert(1);
      else
        v[i % k].insert(2);
    }
    bool ans = true;
    long long int count_0 = 0, count_1 = 0, c_q = 0;
    for (auto s : v) {
      if (s.size() > 1) ans = false;
    }
    for (auto s : v) {
      if (s.empty()) {
        c_q++;
        continue;
      }
      if (*s.begin() == 1) {
        count_1++;
        continue;
      } else {
        count_0++;
        continue;
      }
    }
    if (c_q < abs(count_0 - count_1)) {
      ans = false;
    }
    if (!ans) {
      cout << "NO"
           << "\n";
    } else {
      cout << "YES"
           << "\n";
    }
  }
}
