#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  vector<string> answer(q);
  for (int qq = 0; qq < q; qq++) {
    string s;
    cin >> s;
    int m;
    cin >> m;
    vector<int> b(m);
    for (int i = 0; i < m; i++) cin >> b[i];
    vector<vector<int>> zeros;
    while (true) {
      vector<int> pos;
      for (int i = 0; i < b.size(); i++) {
        if (b[i] == 0) {
          pos.push_back(i);
          b[i] = -23323284;
        }
      }
      if (pos.empty()) break;
      zeros.push_back(pos);
      for (int i = 0; i < m; i++) {
        for (int p : pos) b[i] -= abs(i - p);
      }
    }
    map<char, int> c;
    for (int i = 0; i < s.size(); i++) c[s[i]]++;
    auto j = c.rbegin();
    string t(m, '?');
    for (auto z : zeros) {
      while (j->second < z.size()) j++;
      for (int p : z) {
        t[p] = j->first;
      }
      j++;
    }
    answer[qq] = t;
  }
  for (int i = 0; i < q; i++) cout << answer[i] << endl;
}
