#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, count1 = 0, count2 = 0;
    cin >> n >> k;
    string s, ans = "YES";
    cin >> s;
    for (int i = 0; i < k; i++) {
      if (s[i] == '?') {
        for (int j = i + k; j < n; j += k) {
          if (s[j] != '?') {
            s[i] = s[j];
            break;
          }
        }
      }
    }
    for (int i = 0; i < k; i++) {
      if (s[i] != '?') {
        for (int j = i + k; j < n; j += k) {
          if (s[j] == '?') {
            s[j] = s[i];
          } else if (s[j] != s[i]) {
            ans = "NO";
          }
        }
      }
    }
    if (ans == "YES") {
      for (int i = 0; i < k; i++) {
        if (s[i] == '1') {
          count1++;
        } else if (s[i] == '0') {
          count2++;
        }
      }
      if (count1 <= k / 2 && count2 <= k / 2) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      cout << ans << endl;
    }
  }
}
