#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    map<char, int> m;
    for (int i = 0; i < s.size(); i++) m[s[i]]++;
    vector<vector<int> > groups;
    while (true) {
      vector<int> pos;
      for (int i = 0; i < n; i++)
        if (b[i] == 0) pos.push_back(i);
      if (pos.size() == 0) break;
      groups.push_back(pos);
      for (int i = 0; i < n; i++) {
        if (b[i] == 0)
          b[i] = INT_MAX;
        else
          for (int p : pos) b[i] -= abs(i - p);
      }
    }
    auto j = m.rbegin();
    string ans(n, '!');
    for (auto g : groups) {
      while (j->second < g.size()) j++;
      for (int p : g) ans[p] = j->first;
      j++;
    }
    cout << ans << "\n";
  }
}
