#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    string s;
    cin >> s >> n;
    string ans(n, '.');
    int a[n];
    for (int &i : a) cin >> i;
    char now = 'z';
    while (now >= 'a') {
      vector<int> v;
      for (int i = 0; i < n; ++i) {
        if (ans[i] != '.') continue;
        int tmp = 0;
        for (int j = 0; j < n; ++j)
          if (ans[j] != '.') tmp += abs(i - j);
        if (tmp == a[i]) v.push_back(i);
      }
      while (count(s.begin(), s.end(), now) < v.size()) --now;
      for (int i : v) ans[i] = now;
      --now;
    }
    cout << ans << '\n';
  }
}
