#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string second;
    cin >> second;
    vector<char> v(k, '?');
    bool ok = true;
    for (int i = 0; i < k; i++) {
      for (int j = i; j < second.length(); j += k) {
        if (second[j] == '?') continue;
        if (v[i] == '?' || v[i] == second[j])
          v[i] = second[j];
        else if (v[i] != second[j]) {
          ok = false;
          break;
        }
      }
    }
    if (!ok) {
      cout << "NO" << endl;
      continue;
    }
    int z = 0, o = 0;
    for (int i = 0; i < k; i++) {
      if (v[i] == '0')
        z++;
      else if (v[i] == '1')
        o++;
    }
    if (z > k / 2 || o > k / 2)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
