#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, g, k, m, mx = 0, mn = 1e9, c, res, c1, x, y, w, z, c2;
  scanf("%lld", &t);
  for (long long int ca = 1; ca <= t; ca++) {
    string a;
    cin >> a;
    cin >> n;
    vector<long long int> b(n);
    char ans[n];
    for (long long int i = 0; i < n; i++) cin >> b[i];
    long long int cnt0 = 0;
    map<char, long long int> mp;
    long long int l = a.length();
    for (long long int i = 0; i < l; i++) {
      x = a[i];
      mp[x]++;
    }
    sort(a.begin(), a.end());
    long long int j = l - 1;
    vector<long long int> help;
    while (true) {
      cnt0 = 0;
      help.clear();
      for (long long int i = 0; i < n; i++) {
        if (b[i] == 0) {
          help.push_back(i);
          cnt0++;
        }
      }
      if (cnt0 == 0) break;
      if (cnt0 <= mp[a[j]]) {
        for (long long int k = 0; k < cnt0; k++) {
          ans[help[k]] = a[j];
        }
        j -= mp[a[j]];
      } else {
        j -= mp[a[j]];
        continue;
      }
      for (long long int k = 0; k < cnt0; k++) {
        long long int ind = help[k];
        for (long long int id = 0; id < n; id++) {
          if (b[id] != 0 && b[id] != -1) {
            b[id] -= abs(id - ind);
          } else if (b[id] == 0)
            b[id] = -1;
        }
      }
    }
    for (long long int i = 0; i < n; i++) cout << ans[i];
    cout << endl;
  }
}
