#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long res[300001];
    for (long long i = 0; i < n; i++) res[i] = -1;
    bool ans = true;
    for (long long i = 0; i < n; i++) {
      if (res[i % k] == -1) {
        if (s[i] == '0') res[i % k] = 0;
        if (s[i] == '1') res[i % k] = 1;
      } else {
        if (s[i] == '0' && res[i % k] == 1 || s[i] == '1' && res[i % k] == 0) {
          ans = false;
          break;
        }
      }
    }
    long long cnt[2] = {0};
    for (long long i = 0; i < k; i++) {
      if (res[i] != -1) cnt[res[i]]++;
    }
    if (cnt[0] > k / 2 || cnt[1] > k / 2) ans = false;
    if (ans)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
