Please help in debugging Divisible By 8 (CodeChef Starters 103)

I am getting WA

This is the code I have written

</>
include
include <stdio.h>

using namespace std;
int numFromDig(int o, int t, int h) {
int v = (h100) + (t10) + o;
return v;
}
int main() {
int t;
cin >> t;
while(t–) {
int len;
cin >> len;
string num;
cin >> num;

    int b[3] = {num[len-1]-'0', num[len-2]-'0', num[len-3]-'0'}; // ones...tens...hundreth digit
    //cout << num[bb]-'0' << " " << num[bb-1]-'0' << " " << num[bb-2]-'0' << endl;
    if(len == 1) {
        cout << 8 << endl;
    }
    else if(len == 2)  {
        int h = (num[len-1]-'0') + ((num[len-2]-'0')*10);
        if(h%8==0) {
            cout << num << endl;
        }
        for(int pos = 0;pos<2;pos++) {
            int k1=b[0], k2=b[1];
            int s = 0;
            if(pos == 1) s = 1;
            else s = 0;
            for(int val=s; val<10;val++) {
                b[pos] = val;
                h = numFromDig(b[0], b[1], 0);
                if(h%8==0) {
                    cout << b[1] << b[0] << endl;
                    pos = 100;
                    val = 100;
                }
            }
        }
    }
    else {
        int h = numFromDig(b[0], b[1], b[2]);
        if(h%8==0) {
            cout << num << endl;
        }
        else {
            int k1 = b[0], k2=b[1], k3=b[2];
            for(int pos=0;pos<3;pos++) {
                b[0] = k1;
                b[1] = k2;
                b[2] = k3;
                int s = 0;
                if(len==3) {
                    if(pos == 2) {
                        s = 1;
                    }
                    else {
                        s = 0;
                    }
                }
                for(int val=s;val<10;val++) {
                    b[pos] = val;
                    h = numFromDig(b[0], b[1], b[2]);
                    if(h%8==0) {
                        for(int u=0;u<len-3;u++) {
                            cout << num[u];
                        }
                        cout << b[2] << b[1] << b[0] << endl;
                        val = 15;
                        pos = 5; // to break both loop
                    }
                }
            }
        }
    }
    
    //cout << b[0] << " " << b[1] << " " << b[2] << endl;
}
return 0;

}

@shobhit32t
can u plzz send your submission link?

https://www.codechef.com/viewsolution/1026155256

@shobhit32t
plzz refer the following solution for better understanding of the logic.

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

int main() {
	int t;
	cin>>t;
	while(t--){
	    int n,v;
	    string s;
	    cin>>n>>s;
	    if(n<=3) v=stoi(s);
	    else v=stoi(s.substr(n-3));
	    if(v%8==0) cout<<s<<endl;
	    else{
	        int ans;
	        if(n==1) ans=0;
	        else if(n==2) ans=stoi(s.substr(n-2,1));
	        else ans=stoi(s.substr(n-3,2));
	        if(ans%4==0) s.back()='8';
	        else if(ans%4==1) s.back()='6';
	        else if(ans%4==2) s.back()='4';
	        else s.back()='2';
	        cout<<s<<endl;
	    }
	}
	return 0;
}