#include <bits/stdc++.h>
using namespace std;
long long modd = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q, t, n, m, x, i, j, k, p, r, zero = 0, one = 0, dou = 0;
  cin >> q;
  while (q--) {
    cin >> n >> k;
    string s;
    cin >> s;
    bool ispos = true;
    int oneCount = 0, zeroCount = 0;
    for (j = 0; j < k; j++) {
      zero = 0;
      one = 0;
      dou = 0;
      for (i = j; i < n; i += k) {
        if (s[i] == '0')
          zero++;
        else if (s[i] == '1')
          one++;
        else
          dou++;
        if (zero != 0 && one != 0) {
          ispos = false;
          break;
        }
      }
      if (!ispos) {
        break;
      }
      if (s[j] == '?' && !(one == 0 && zero == 0)) {
        s[j] = (one == 0) ? '0' : '1';
      }
      if (s[j] == '1')
        oneCount++;
      else if (s[j] == '0')
        zeroCount++;
    }
    if (ispos && oneCount <= k / 2 && zeroCount <= k / 2) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
