#include <bits/stdc++.h>
using namespace std;
int t, ls, lf, val[51], ans[51], zero[51], tot;
string s;
struct alph {
  int c, s;
} a[27];
bool cmp(alph l, alph r) {
  if (l.s == 0) return false;
  if (r.s == 0) return true;
  return l.c > r.c;
}
bool vis[51];
void dfs(int indi, int amo) {
  tot = 0;
  for (int i = 1; i <= lf; i++) {
    if (val[i] == 0 && !vis[i]) tot++, zero[tot] = i, vis[i] = true;
  }
  while (a[indi].s < tot) indi++;
  for (int i = 1; i <= tot; i++) {
    ans[zero[i]] = a[indi].c;
  }
  for (int i = 1; i <= tot; i++) {
    for (int j = 1; j <= lf; j++) {
      if (val[j] != 0) val[j] -= abs(zero[i] - j);
    }
  }
  amo -= tot;
  indi++;
  if (amo > 0) dfs(indi, amo);
}
int main() {
  cin >> t;
  while (t--) {
    for (int i = 1; i <= 26; i++) a[i].c = i, a[i].s = 0;
    cin >> s;
    ls = s.size();
    for (int i = 0; i < ls; i++) a[int(s[i]) - 96].s++;
    sort(a + 1, a + 27, cmp);
    cin >> lf;
    for (int i = 1; i <= lf; i++) cin >> val[i];
    memset(vis, false, sizeof(vis));
    memset(ans, 0, sizeof(ans));
    dfs(1, lf);
    for (int i = 1; i <= lf; i++) cout << char(ans[i] + 96);
    cout << endl;
  }
  return 0;
}
