#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int INF = 1e18;
long long int po(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b % 2 == 1) {
      re = (re * a);
    }
    a = (a * a);
    b >>= 1;
  }
  return re;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  cin >> test;
  while (test--) {
    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool f = 1;
    int u = k / 2;
    int o = 0, z = 0;
    int y = -1;
    for (int i = (0); i < (k); i++) {
      y = -1;
      for (int j = i; j < n; j += k) {
        if (s[j] == '1') {
          if (y == 0) {
            f = 0;
            break;
          }
          y = 1;
        } else if (s[j] == '0') {
          if (y == 1) {
            f = 0;
            break;
          }
          y = 0;
        }
      }
      if (f == 0) break;
      if (y == 1)
        z++;
      else if (y == 0)
        o++;
    }
    if (o > u || z > u) f = 0;
    if (f)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
