#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
long long prime[N], cnt;
long long phi[N];
bool vis[N];
void initphi(int n) {
  phi[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) {
      prime[cnt++] = i;
      phi[i] = i - 1;
    }
    for (int j = 0; prime[j] <= n / i; j++) {
      int t = prime[j] * i;
      vis[t] = 1;
      if (i % prime[j] == 0) {
        phi[t] = phi[i] * prime[j];
        break;
      }
      phi[t] = phi[i] * (prime[j] - 1);
    }
  }
}
long long n, m, k, t, tmp, b[maxn], a[200];
string s;
char ans[200];
void run() {
  cin >> s >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) cin >> b[i];
  m = s.size();
  memset(a, 0, sizeof a);
  for (int i = 0; i < m; i++) {
    a[s[i]]++;
  }
  vector<int> num;
  int now = 'z';
  while (sum < n) {
    for (int i = 0; i < n; i++) {
      if (b[i] == 0) num.push_back(i);
    }
    int sz = num.size();
    sum += sz;
    for (; now >= 'a'; now--) {
      if (a[now] >= sz) {
        for (int i : num) ans[i] = now;
        for (int i = 0; i < n; i++) {
          if (b[i] > 0) {
            for (int j : num) {
              b[i] -= abs(i - j);
            }
          }
        }
        now--;
        break;
      }
    }
    for (int i : num) b[i] = -1;
    num.clear();
  }
  for (int i = 0; i < n; i++) {
    cout << (char)ans[i];
  }
  cout << '\n';
}
int main() {
  cin >> t;
  while (t--) run();
}
