#include <bits/stdc++.h>
using namespace std;
long long t, d, ct, q, ans, l, r, n, m, mx, mn, i, j, k, x, y, z, s;
char ch;
string ss = "", str = "";
map<long long, long long> mp, mpp;
set<long long> st;
long long b[300003];
string a;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  cin >> t;
  while (t--) {
    s = k = d = l = m = mx = mn = r = q = i = j = z = x = y = ct = ans = 0;
    cin >> n >> k >> a;
    for (i = 0; i <= n; i++) b[i] = 2;
    for (i = k; i < n; i++) {
      if ((a[i - k] == '1' && a[i] == '0') ||
          (a[i - k] == '0' && a[i] == '1')) {
        r = 1;
        break;
      }
      if (a[i - k] != '?') a[i] = a[i - k];
      if (a[i] == '1')
        b[i % k] = 1;
      else if (a[i] == '0')
        b[i % k] = 0;
      else
        b[i % k] = 2;
    }
    for (i = 0; i < k; i++) {
      if (a[i] != '?') b[i] = a[i] - '0';
      if (b[i] == 2)
        ct++;
      else if (b[i] == 1)
        s++;
      else
        m++;
    }
    if (m > s + ct || s > ct + m) r = 1;
    if (r)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
