#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
void prints() {}
template <typename T>
void get(T* x, long long int n) {
  for (long long int i = 0; i < n; ++i) {
    cin >> x[i];
  }
}
template <typename T>
void get(T& x, long long int n) {
  for (long long int i = 0; i < n; ++i) {
    cin >> x[i];
  }
}
template <typename T, typename... A>
void print(T x, A... r) {
  cout << x << " ";
  print(r...);
}
template <typename T, typename... A>
void prints(T x, A... r) {
  cout << x << " ";
  prints(r...);
}
const long long int mod = 1e9 + 7;
const long long int N = 1e6 + 1;
bool testcase(long long int t) {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<string> v(k);
  for (long long int i = 0; i < n; ++i) {
    v[i % k] += s[i];
  };
  map<char, long long int> tc;
  for (auto c : s) {
    tc[c]++;
  }
  for (long long int i = 0; i < k; ++i) {
    string z = v[i];
    map<char, long long int> cnt;
    for (auto c : z) {
      cnt[c]++;
    }
    if (cnt['0'] && cnt['1']) {
      return false;
    }
    if (cnt['1']) {
      for (long long int j = i; j < n; j += k) {
        s[j] = '1';
      }
      continue;
    }
    if (cnt['0']) {
      for (long long int j = i; j < n; j += k) {
        s[j] = '0';
      }
      continue;
    }
  };
  map<char, long long int> cnt;
  for (long long int i = 0; i < n;) {
    cnt[s[i]]++;
    if (i >= k) {
      cnt[s[i - k]]--;
    }
    i++;
    if (i >= k) {
      if (abs(cnt['1'] - cnt['0']) > cnt['?']) {
        return false;
      }
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  for (long long int i = 1; i <= t; ++i) {
    if (testcase(i)) {
      print("YES");
    } else {
      print("NO");
    }
  }
  return 0;
}
