IS ANYONE READY TO TELL WHY THIS CODE IS WRONG FOR CAESAR CIPHER PROBLEM?

#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,inp;
cin>>t;
while(t–){
int n;
string s,t,u;
string res=“”;
cin>>n>>s>>t>>u;
int k=(t[0]-s[0]);

for(int i=0;i<n;i++){
    if((int(u[i])+k)>122){
        char c='a'+char((int(u[i])+k)-123);
        res+=c;
    }
    else if((int(u[i])+k)<97){
        res+=(char((int(u[i]))+25-k));
    }
    else {
        res+=char(u[i]+k);
    }
}

cout<<res<<endl;

}
}

This starter problem was really tricky. Here u have approached the problem with the same logic i had approached it and what really was going wrong on my end was that some alphabets due to our formula were going off the alphabet ascii range for ex :

  let say  Q has its equivalent as g , so k should be 16, but your k gives us -9. then if we had to find the equivalent of z , which should be P. But your formula gives us  z(122)+k(-9)== 113 which is R.