#include <bits/stdc++.h>
using namespace std;
long long int a[500005], b[500005];
int main() {
  long long int t, i, j, k, l, x, y, z, n, boro, choto;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    string s, p;
    cin >> s;
    for (i = 0; i < k; i++) p += '?';
    x = 0;
    for (i = 0; i < n; i++) {
      if (p[i % k] == '?') {
        p[i % k] = s[i];
      } else if (p[i % k] != s[i] && s[i] != '?') {
        x = 1;
        break;
      }
    }
    y = 0, z = 0, l = 0;
    for (i = 0; i < k; i++) {
      if (p[i] == '0')
        y++;
      else if (p[i] == '1')
        z++;
      else
        l++;
    }
    boro = max(y, z);
    choto = min(y, z);
    if (choto + l < boro) x = 1;
    if (x)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
