R=range I=input P=998244353 for t in R(int(I())): N,S,E,s=int(I()),I(),0,0 for i in R(N): s+=E+1 if S[i]>'B':E+=1 else:E=s*pow(i+2,-1,P)%P print(s%P)