#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define fi first
#define se second
#define _UN using namespace
using namespace std;
const int INF=0x3f3f3f3f;
int n,A[11]; char S[100];
long F[10][320][11][11];
void addto(long& x,long y){ x+=y; }
void case_main(){
cin>>n>>(S+1);
RNG(i,1,n) cin>>A[i];
memset(F,0,sizeof(F));
auto chk=[](char c1,char c2){ return c1=='?'||c1==c2; };
auto rng=[](char c)->pair<int,int>{ return c=='?'?{0,9}:isdigit(c)?{c-'0',c-'0'}:{0,-1}; }
RNG(i,1,n-1){
auto c1=S[2*i-1],c2=S[2*i];
if(chk(c1,'x')&&chk(c2,'-')){
RNG(p,0,30*(i-1)){
RNG(a,0,10){
auto x=F[i-1][p][10][a];
if(!x) continue;
RNG(b,0,10){
auto q=p+10+a+b;
if(A[i]!=-1&&A[i]!=q) continue;
addto(F[i][q][a][b],x);
}
}
}
}
if(chk(c2,'/')){
auto [l,r]=rng(c1);
RNG(t,l,r){
RNG(p,0,30*(i-1)){
auto x=F[i-1][p][t][10-t];
if(!x) continue;
RNG(a,0,10){
auto q=p+10+a;
if(A[i]!=-1&&A[i]!=q) continue;
RNG(b,0,10) addto(F[i][y][a][b],x);
}
}
}
}
{
auto [l1,r1]=rng(c1);
RNG(s,l1,r1){
int l2,r2; tie(l2,r2)=rng(c2); r2=min(r2,9-s);
RNG(t,l2,r2){
RNG(p,0,30*(i-1)){
auto x=F[i-1][p][s][t];
if(!x) continue;
auto q=p+s+t;
if(A[i]!=-1&&A[i]!=q) continue;
RNG(a,0,10){
RNG(b,0,10) addto(F[i][y][a][b],x);
}
}
}
}
}
}
long ans=0;
{
auto c1=S[n*2-1],c2=S[n*2],c3=S[n*2+1];
if(chk(c1,x)&&chk(c2,x)&&chk(c3,x)){
RNG(p,0,30*(n-1)){
auto x=F[n-1][p][10][10];
if(!x) continue;
int q=p+30;
if(A[i]!=-1&&A[i]!=q) continue;
addto(ans,x);
}
}
if(chk(c1,x)&&chk(c2,x)){
auto [l,r]=rng(c3);
RNG(t,l,r){
RNG(p,0,30*(n-1)){
auto x=F[n-1][p][10][10];
if(!x) continue;
int q=p+20+t;
if(A[i]!=-1&&A[i]!=q) continue;
addto(ans,x);
}
}
}
}
}
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
// freopen("/dev/null","w",stderr);
#else
// freopen("tree.in","r",stdin);
// freopen("tree.out","w",stdout);
#endif
int cas; cin>>cas;
RNG(_,1,cas) case_main();
}