#include
#include
#include
#include
using namespace std;
int main()
{
//Number of testcases
int T;
cin >> T;
while (T--)
{
//Number of questions
int n;
cin >> n;
//Correct answers for questions
string corrAns;
cin >> corrAns;
//Answers given by Chef to the questions
string chefAns;
cin >> chefAns;
//Vector of winnings for 0, 1, ..., n Chef's correct answers in row,
//starting from first
vector w(n + 1);
for (int i = 0; i <= n; ++i)
cin >> w[i];
//Counting number of Chef's correct answers
int cntCorr = 0;
for (int i = 0; i < n; ++i)
if (corrAns[i] == chefAns[i])
++cntCorr;
//If Chef answered correctly to all the questions,
//then his winning is equal to w[n], because Chef will get n
//answers in row in any order of questions
if (cntCorr == n)
cout << w[n] << endl;
//Otherwise Chef is able to get from 0 to cntCorr answers
//in row, so we must find maximum among corresponding winnings
else
{
int ans = 0;
for (int i = 0; i <= cntCorr; ++i)
ans = max(ans, w[i]);
cout << ans << endl;
}
}
return 0;
}