#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int tt = 1, n, m, k = 0, i, j, p, q;
  long long int a, b, c, d, h, w, u, v, x, y, t = 0;
  long long int ans = 0;
  long long int l = 0, r = 0;
  bool poss = true;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string s;
  time_t tic, toc;
  tic = clock();
  cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    cin >> s >> m;
    n = (long long int)(s).size();
    string t(m, '0');
    vector<long long int> brr(m);
    for (auto &z : brr) cin >> z;
    vector<long long int> alpcnt(26, 0);
    for (i = 0; i < n; i++) {
      alpcnt[s[i] - 'a']++;
    }
    vector<long long int> temp(m, 0);
    vector<long long int> marked(m, 0);
    j = 25;
    vector<long long int> pos;
    long long int rem = m;
    while (rem) {
      pos.clear();
      for (i = 0; i < m; i++) {
        if (temp[i] == brr[i] and marked[i] == 0) {
          pos.push_back(i);
          marked[i] = 1;
        }
      }
      while (j >= 0 and alpcnt[j] < (long long int)(pos).size()) {
        j--;
      }
      for (auto &z : pos) {
        t[z] = 'a' + j;
      }
      j--;
      if (j < 0) break;
      rem -= (long long int)(pos).size();
      for (i = 0; i < m; i++) {
        if (!marked[i]) {
          for (auto &z : pos) {
            temp[i] += abs(i - z);
          }
        }
      }
    }
    cout << t << "\n";
  }
  return 0;
}
