#include <cstdio>
#include <cstring>
#include <list>
#include <algorithm>
using namespace std;
const int MAX=1e6;
const int MAXP=(1e5)+1;
char message[MAX+1], encrypted[MAX+1];
int key[MAXP], both[MAX], known[MAX], nkn;
list<int> tofind;
bool feasible(int n){
memset(key, -1, sizeof(int)*n);
for(int it=0; it<nkn; it++){
int pos=known[it];
if(key[pos%n]==-1) key[pos%n]=both[pos];
else if(key[pos%n]!=both[pos])return 0;
}
return 1;
}
int main(){
int t; scanf("%d", &t);
while(t--){
int m; scanf("%d", &m);
scanf("%s %s", message, encrypted);
tofind.clear();
nkn=0;
int ntofind = 0;
for(int i=0; message[i]!=0; i++)
if(message[i]!='*'&&encrypted[i]!='*'){
known[nkn++]=i;
both[i]=(26+encrypted[i]-message[i])%26;
}
else if(message[i]=='*'&&encrypted[i]!='*')
tofind.push_back(i), ntofind++;
list<int>::iterator it;
m = min(m, (int)strlen(message));
for(int n=m/2 +1; n<=m; n++)
if(feasible(n)){
it=tofind.begin();
while(it!=tofind.end())
if(key[(*it)%n]==-1){
message[*it]='*';
it=tofind.erase(it);
}
else if(message[*it]=='*'){
message[*it]=(encrypted[*it]-'A'+26-key[(*it)%n])%26 + 'A';
it++;
}
else if(message[*it] != (encrypted[*it]-'A'+26-key[(*it)%n])%26 + 'A'){
message[*it]='*';
it=tofind.erase(it);
}
else it++;
}
printf("%s\n", message);
}
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTUFYPTFlNjsKY29uc3QgaW50IE1BWFA9KDFlNSkrMTsKY2hhciBtZXNzYWdlW01BWCsxXSwgZW5jcnlwdGVkW01BWCsxXTsKaW50IGtleVtNQVhQXSwgYm90aFtNQVhdLCBrbm93bltNQVhdLCBua247Cmxpc3Q8aW50PiB0b2ZpbmQ7CmJvb2wgZmVhc2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