#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string second;
    cin >> second;
    int m;
    cin >> m;
    vector<int> ltr(26, 0);
    for (int i = 0; i < second.size(); i++) {
      ltr[second[i] - 'a']++;
    }
    vector<int> tmp;
    int tmp1;
    unordered_map<int, int> hm;
    for (int i = 0; i < m; i++) {
      cin >> tmp1;
      hm[i] = tmp1;
    }
    vector<char> ans(m);
    int j = 25;
    while (!hm.empty()) {
      for (auto it = hm.begin(); it != hm.end(); it++) {
        if (it->second == 0) tmp.push_back(it->first);
      }
      for (int t1 = 0; t1 < tmp.size(); t1++) {
        hm.erase(tmp[t1]);
      }
      for (auto it = hm.begin(); it != hm.end(); it++) {
        for (int p = 0; p < tmp.size(); p++)
          (it->second) -= abs(tmp[p] - (it->first));
      }
      while (j >= 0 && ltr[j] < tmp.size()) j--;
      for (int x = 0; x < tmp.size(); x++) ans[tmp[x]] = char(j + 'a');
      j--;
      tmp.clear();
    }
    for (int i = 0; i < m; i++) cout << ans[i];
    cout << endl;
  }
  return 0;
}
