#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, k;
  string s;
  cin >> t;
  while (t--) {
    cin >> n >> k >> s;
    char st[k];
    memset(st, '?', sizeof(st));
    for (int i = 0; i < n; i++) {
      if (s[i] != '?') {
        if (st[i % k] == '?') {
          st[i % k] = s[i];
        }
      }
    }
    bool check = true;
    long long cnt[k];
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++) {
      if (s[i] != '?') {
        if (s[i] == st[i % k])
          cnt[i % k]++;
        else {
          check = false;
          break;
        }
      } else {
        cnt[i % k]++;
      }
    }
    if (!check) {
      cout << "NO" << endl;
      continue;
    }
    long long cnt0 = 0, cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < k; i++) {
      if (st[i] == '1')
        cnt1++;
      else if (st[i] == '0')
        cnt0++;
      else
        cnt2++;
    }
    long long dif = fabs(cnt1 - cnt0);
    if (cnt1 != cnt0) {
      if (cnt2 >= dif) {
        cnt2 -= dif;
        if (cnt2 % 2 == 0)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      } else
        cout << "NO" << endl;
    } else {
      if (cnt2 % 2 == 0) cout << "YES" << endl;
    }
  }
}
