#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = s.size();
    long long m;
    cin >> m;
    long long b[m];
    for (long long i = 0; i < m; i++) cin >> b[i];
    long long a[26] = {0};
    for (long long i = 0; i < n; i++) a[s[i] - 'a']++;
    long long mx = 25;
    string ans;
    ans.resize(m);
    while (1) {
      long long x = 0;
      vector<long long> in;
      for (long long i = 0; i < m; i++)
        if (b[i] == 0) {
          x++;
          in.push_back(i);
        }
      if (x == 0) break;
      char c;
      for (long long i = mx; i >= 0; i--) {
        if (a[i] >= x) {
          c = 'a' + i;
          mx = i - 1;
          break;
        }
      }
      a[c - 'a'] -= x;
      for (long long i = 0; i < m; i++)
        if (b[i] == 0) ans[i] = c;
      for (long long i = 0; i < m; i++) {
        long long ct = 0;
        if (b[i] == 0) b[i] = -1;
        for (long long j = 0; j < in.size(); j++) ct += abs(i - in[j]);
        b[i] -= ct;
      }
    }
    cout << ans << endl;
  }
}
