#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    map<char, int> mm;
    for (int i = 0; i < s.size(); i++) {
      mm[s[i]]++;
    }
    int n;
    cin >> n;
    int m[n];
    for (int i = 0; i < n; i++) {
      cin >> m[i];
    }
    string ss(n, '?');
    vector<vector<int> > p;
    while (1) {
      vector<int> pos;
      for (int i = 0; i < n; i++) {
        if (m[i] == 0) {
          pos.push_back(i);
        }
      }
      if (pos.size() == 0) break;
      p.push_back(pos);
      for (int i = 0; i < n; i++) {
        if (m[i] == 0) {
          m[i] = INT_MAX;
        } else {
          for (int x : pos) {
            m[i] -= abs(i - x);
          }
        }
      }
    }
    auto j = mm.rbegin();
    for (auto g : p) {
      while (j->second < g.size()) j++;
      for (int xx : g) {
        ss[xx] = j->first;
      }
      j++;
    }
    cout << ss << endl;
  }
  return 0;
}
