CAKEDOOM- not able to find the bug

#include <bits/stdc++.h>
using namespace std;

typedef long long int llint;
#define limit 100001

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

llint t;
cin >> t;

while (t--)
{
    int k;
    cin >> k;
    cin.ignore();

    string s;
    getline(cin, s);
    int len = s.length();
    int sint[len];
    for (int i = 0; i < len; i++)
    {
        if (s[i] == '?')        sint[i] = -1;
        else                    sint[i] = s[i] - '0';
    }
    //mapped s to s int.
    bool valid = true;

    if (len == 1)       sint[0] = sint[0] == -1 ? 0 : sint[0];
    else if (k == 2)
    {
        if (len % 2 != 0)   valid = false;
        else
        {
            int temp[2][len];
            for (int i = 0; i < len; i++)
            {
                temp[0][i] = k % 2;
                temp[1][i] = (++k) % 2;
            }
            bool tempvalid;
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < len; i++)
                {
                    if (sint[i] == temp[j][i] || sint[i] == -1)         tempvalid = true;
                    else
                    {
                        tempvalid = false;
                        break;
                    }
                }
                if (tempvalid)
                {
                    for (int i = 0; i < len; i++)        sint[i] = temp[j][i];
                    break;
                }
            }
        }
    }
    else
    {
        for (int i = 0; i < len && valid; i++)
        {
            int prev = sint[(len+i-1)%len];
            int next = sint[(len+i+1)%len];
            if (sint[i] == -1)
            {
                for (int j = 0; j < k; j++)
                {
                    if (j != prev && j != next)
                    {
                        sint[i] = j;
                        break;
                    }
                }
                if (sint[i] == -1)        valid = false;
            }
            else if (prev == sint[i] || next == sint[i])       valid = false;
        }
    }

    if (valid)
    {
        string ans = "";
        for (int i = 0; i < len; i++)   ans += to_string(sint[i]);
        cout <<ans<< '\n';
    }
    else    cout << "NO" << '\n';
}

}

Please tell me why this code is giving WA. I am stuck since the last 1 day.