#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> d0(k);
  vector<int> d1(k);
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    if (c == '0') {
      d0[i % k] = 1;
    }
    if (c == '1') {
      d1[i % k] = 1;
    }
  }
  int bad = 0;
  int c0 = 0;
  int c1 = 0;
  for (int i = 0; i < k; i++) {
    bad |= (d0[i] && d1[i]);
    c0 += d0[i];
    c1 += d1[i];
  }
  if (!bad && c0 <= k / 2 && c1 <= k / 2) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
}
