func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {}   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int maxn = 3e5 + 5;   int cnt[maxn];   int main() {     int t;     scanf( %d , &t);     while (t--) {       string s;       int n, k;       cin >> n >> k >> s;       int ans = 1;       for (int i = 0; i < k; ++i) cnt[i] = 0;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  ? ) continue;         if ((s[i] ==  0  && cnt[i % k] == 1) ||             (s[i] ==  1  && cnt[i % k] == -1)) {           ans = 0;           break;         }         cnt[i % k] = s[i] ==  0  ? -1 : 1;       }       int cnt1 = 0, cnt0 = 0;       for (int i = 0; i < n; ++i)         if (cnt[i % k]) s[i] = cnt[i % k] == -1 ?  0  :  1 ;       for (int i = 0; i < k; ++i) {         if (s[i] ==  1 )           cnt1++;         else if (s[i] ==  0 )           cnt0++;       }       if (2 * cnt1 > k || 2 * cnt0 > k) ans = 0;       puts(ans ?  YES  :  NO );     }   }   