#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int t, n, k, A[maxn];
string s;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k >> s;
    bool flag = true;
    int a = 0, b = 0;
    for (int i = k; i < n; i++) {
      if (s[i % k] == '?') {
        s[i % k] = s[i];
      }
      if (s[i % k] != s[i] && s[i] != '?') {
        flag = false;
      }
    }
    for (int i = 0; i < k; i++) {
      if (s[i] == '0') a++;
      if (s[i] == '1') b++;
    }
    if (max(a, b) > k / 2) flag = false;
    cout << (flag ? "YES" : "NO") << endl;
  }
}
