#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
const int32_t mod = 1e9 + 7;
const long long INF = 1e18;
const long long N = 1e5 + 5, M = 103;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long total_one = 0, total_zero = 0;
  for (long long i = 0; i < k; ++i) {
    long long one = 0, zero = 0;
    for (long long j = i; j < n; j += k) {
      if (s[j] == '0')
        zero++;
      else if (s[j] == '1')
        one++;
    }
    if (one > 0 && zero > 0) {
      cout << "NO\n";
      return;
    }
    if (one > 0)
      s[i] = '1';
    else if (zero > 0)
      s[i] = '0';
  }
  long long one = 0, ques = 0, zero = 0;
  for (long long i = 0; i < k; ++i) {
    if (s[i] == '1')
      one++;
    else if (s[i] == '0')
      zero++;
    else
      ques++;
  }
  long long diff = abs(one - zero);
  if (ques < diff)
    cout << "NO\n";
  else
    cout << "YES\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
