#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args>
inline string arrStr(T arr, int n) {
  stringstream s;
  s << "[";
  for (int i = 0; i < n - 1; i++) s << arr[i] << ",";
  s << arr[n - 1] << "]";
  return s.str();
}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template <typename T>
inline void __evars_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T>
inline void __evars_out_var(T* val) {
  cerr << arrStr(val, 10);
}
template <typename T>
inline void __evars_out_var(T val) {
  cerr << val;
}
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template <typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __evars_out_var(a);
  cerr << "; ";
  __evars(++it, args...);
}
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
long long modpower(long long base, long long power, long long mod) {
  if (base == 0 || base == 1) return base;
  long long res = 1;
  while (power) {
    if (power % 2) {
      res = (res * base) % mod;
      power--;
    }
    base = (base * base) % mod;
    power /= 2;
  }
  return (res + mod) % mod;
}
long long const INF = 1LL << 60LL;
double const pi = 3.14159265358979323846264338327950;
long long const MAX = 1e6;
long long mod = 1000000007;
long long n, k;
string s;
bool valid(string str) {
  long long c1 = 0;
  long long c0 = 0;
  long long c = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '1')
      c1++;
    else if (str[i] == '0')
      c0++;
    else
      c++;
  }
  if (abs(c1 - c0) <= c)
    return 1;
  else
    return 0;
}
void solve() {
  cin >> n >> k;
  cin >> s;
  vector<string> v;
  bool flag = true;
  for (int i = 0; i < n; i = i + k) {
    string str = s.substr(i, min(k, n - i));
    v.push_back(str);
    if (str.size() == k && !valid(str)) {
      flag = false;
      break;
    }
  }
  string temp;
  for (int i = 0; i < k; i++) {
    long long c1 = 0;
    long long c0 = 0;
    for (int j = 0; j < v.size(); j++) {
      if (i < v[j].size()) {
        if (v[j][i] == '1') c1 = 1;
        if (v[j][i] == '0') c0 = 1;
      }
    }
    if (c1 + c0 == 2) {
      flag = false;
      break;
    }
    for (int j = 0; j < v.size(); j++) {
      if (i < v[j].size()) {
        if (c1 == 1 && v[j][i] == '?') v[j][i] = '1';
        if (c0 == 1 && v[j][i] == '?') v[j][i] = '0';
      }
    }
  }
  for (int j = 0; j < v.size(); j++) {
    temp += v[j];
  }
  if (!valid(temp.substr(0, k))) flag = false;
  long long r = k - 1;
  long long l = 0;
  while (r < n - 1) {
    if (s[l] != s[r + 1] && s[l] != '?' && s[r + 1] != '?') {
      flag = false;
      break;
    }
    if (s[r + 1] == '?') s[r + 1] = s[l];
    if (s[l] == '?') s[l] = s[r + 1];
    l++;
    r++;
  }
  if (flag) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(30);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
