#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long pow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  while (b) {
    if (b % 2) {
      ans *= a;
      ans %= mod;
    }
    b /= 2;
    a *= a;
    a %= mod;
  }
  return ans;
}
long long inv(long long a) { return pow(a, mod - 2); }
long long mul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
struct cmp {
  bool operator()(pair<long long, long long> a,
                  pair<long long, long long> b) const {
    long long x = a.first;
    long long y = b.first;
    return x >= y;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(15);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string s;
    long long m;
    cin >> s >> m;
    long long a[m];
    vector<pair<long long, long long>> q;
    for (long long i = 0; i < m; i++) {
      cin >> a[i];
      q.push_back({a[i], i + 1});
    }
    long long cnt[26];
    memset(cnt, 0, sizeof cnt);
    for (long long i = 0; i < s.size(); i++) cnt[s[i] - 'a']++;
    string ans(m + 1, '0');
    while (q.size()) {
      sort(q.begin(), q.end());
      long long z = 0;
      while (z < q.size() && !q[z].first) z++;
      for (long long i = 0; i < z; i++) {
        for (long long j = z; j < q.size(); j++) {
          q[j].first -= abs(q[j].second - q[i].second);
        }
      }
      char p = 'a';
      for (long long i = 25; i >= 0; i--) {
        if (cnt[i] >= z) {
          p += i;
          cnt[i] = 0;
          break;
        }
        cnt[i] = 0;
      }
      for (long long i = 0; i < z; i++) {
        ans[q[i].second] = p;
      }
      reverse(q.begin(), q.end());
      while (z) z--, q.pop_back();
    }
    for (long long i = 0; i < m; i++) cout << ans[i + 1];
    cout << endl;
  }
  return 0;
}
