#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k, i;
    cin >> n >> k;
    vector<pair<set<char>, char>> v(k);
    string second;
    cin >> second;
    for (i = 0; i < n; i++) (v[i % k].first).insert(second[i]);
    bool poss = true;
    long long int c1 = 0, c0 = 0;
    for (i = 0; i < k; i++) {
      if ((v[i].first).find('1') != (v[i].first).end() &&
          (v[i].first).find('0') != (v[i].first).end())
        poss = false;
      else if ((v[i].first).size() == 3)
        poss = false;
      else if ((v[i].first).find('1') != (v[i].first).end()) {
        v[i].second = '1';
        c1++;
      } else if ((v[i].first).find('0') != (v[i].first).end()) {
        v[i].second = '0';
        c0++;
      }
    }
    if (c1 > k / 2 || c0 > k / 2) poss = false;
    if (poss)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
