#include <bits/stdc++.h>
using namespace std;
long double eps = (long double)1 / 1e9;
long long inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
long long sqr(long long a) { return a * a; }
long long qb(long long a) { return a * a * a; }
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long binpow(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
long long binmult(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod
                    : (2 * binmult(a, b / 2, mod)) % mod)
           : 0;
}
long long b[51], kl[27];
bool used[51];
char ans[51];
int main() {
  cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0);
  long long q, n, i, j, ps, kt;
  string a;
  cin >> q;
  while (q--) {
    cin >> a >> n;
    ps = 25;
    for (i = 0; i < 26; i++) kl[i] = 0;
    for (i = 0; i < a.size(); i++) kl[a[i] - 'a']++;
    for (i = 1; i <= n; i++) cin >> b[i], used[i] = 0;
    while (1) {
      kt = 0;
      for (i = 1; i <= n; i++)
        if (!b[i] && !used[i]) kt++;
      if (!kt) break;
      while (kl[ps] < kt) ps--;
      vector<long long> vc;
      for (i = 1; i <= n; i++)
        if (!b[i] && !used[i]) used[i] = 1, vc.push_back(i);
      for (auto f : vc) {
        ans[f] = 'a' + ps;
        for (j = 1; j <= n; j++)
          if (!used[j]) b[j] -= abs(j - f);
      }
      ps--;
    }
    for (i = 1; i <= n; i++) cout << ans[i];
    cout << '\n';
  }
  return 0;
}
