#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  int n;
  cin >> s >> n;
  vector<int> b(n);
  for (int& i : b) cin >> 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.empty()) 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);
      }
    }
  }
  map<char, int> cnt;
  for (char a : s) cnt[a]++;
  auto j = cnt.rbegin();
  string t(n, '?');
  for (auto i : groups) {
    while (j->second < (int)i.size()) j++;
    for (auto p : i) t[p] = j->first;
    j++;
  }
  cout << t << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  int test;
  cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}
