#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int t;
  cin >> t;
  while (t--) {
    string s;
    int n;
    vector<pair<int, int> > vpi;
    char ans[51] = {0};
    cin >> s;
    map<char, int> vc;
    for (int i = 0; i < s.length(); ++i) ++vc[s[i]];
    cin >> n;
    for (int i = 0; i < n; ++i) {
      int t;
      cin >> t;
      vpi.push_back(make_pair(t, i));
    }
    for (auto iter = vc.rbegin(); iter != vc.rend(); ++iter) {
      sort(vpi.begin(), vpi.end());
      int i, ct = 0;
      for (i = 0; i < vpi.size(); ++i) {
        if (vpi[i].first == 0) {
          ++ct;
        } else {
          break;
        }
      }
      while (iter->second < ct) ++iter;
      for (int j = 0; j < ct; ++j) ans[vpi[j].second] = iter->first;
      for (; i < vpi.size(); ++i) {
        for (int j = 0; j < ct; ++j)
          vpi[i].first -= abs(vpi[i].second - vpi[j].second);
      }
      while (ct--) {
        vpi.erase(vpi.begin());
      }
    }
    cout << ans << endl;
  }
  return 0;
}
