#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
using namespace std;
const long long md = 1e9 + 7;
const long long N = 2e5 + 11;
const long long inf = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  long long q;
  cin >> q;
  while (q--) {
    long long n, k, A = 0, B = 0, C = 0;
    cin >> n >> k;
    string s, z = "YES\n";
    cin >> s;
    queue<long long> d;
    for (int i = 0; i < k; i++) {
      long long j = i, a = 0, b = 0;
      while (j < n) {
        if (s[j] == '0') a++;
        if (s[j] == '1') b++;
        j += k;
      }
      if (a != 0 && b != 0) z = "NO\n";
      if (a != 0) A++;
      if (b != 0) B++;
      if (a == 0 && b == 0) C++;
    }
    if (A > B + C) z = "NO\n";
    if (B > A + C) z = "NO\n";
    cout << z;
  }
}
