#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, sum = 0, o = 0, z = 0;
    bool f = 0;
    cin >> n >> k;
    string s;
    cin >> s;
    for (int i = k; i < n; i++) {
      if (s[i] == '0') {
        if (s[i % k] == '1')
          f = 1;
        else
          s[i % k] = '0';
      } else if (s[i] == '1') {
        if (s[i % k] == '0')
          f = 1;
        else
          s[i % k] = '1';
      }
    }
    for (int i = 0; i < k; i++) {
      if (s[i] == '1')
        o++;
      else if (s[i] == '0')
        z++;
    }
    if (z <= k / 2 && o <= k / 2 && !f)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
}
