#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long MAXN = 50 + 10;
const long long mod = 998244353;
const long long inf = 1e18;
const long long mo = 1e9 + 7;
int q, n, m;
char s[MAXN], t[MAXN];
int vis[MAXN], b[MAXN];
int getChar(int cnt) {
  for (int i = 25; i >= 0; i--) {
    if (vis[i] >= cnt) return i;
  }
}
int check() {
  for (int i = 1; i <= m; i++)
    if (t[i] == '\0') return 1;
  return 0;
}
int main() {
  scanf("%d", &q);
  while (q--) {
    memset(vis, 0, sizeof(vis));
    memset(t, 0, sizeof(t));
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    for (int i = 1; i <= n; i++) vis[s[i] - 'a']++;
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
    int flag = 0;
    while (check()) {
      flag--;
      int cnt = 0, pos;
      for (int i = 1; i <= m; i++)
        if (b[i] == 0) cnt++;
      for (int i = 1; i <= m; i++) {
        if (b[i] == 0) {
          pos = getChar(cnt);
          t[i] = pos + 'a';
          b[i] = flag;
        }
      }
      for (int i = pos; i <= 25; i++) vis[i] = 0;
      for (int i = 1; i <= m; i++) {
        if (b[i] == flag) {
          for (int j = 1; j <= m; j++) {
            if (b[j] > 0) b[j] -= abs(i - j);
          }
        }
      }
    }
    for (int i = 1; i <= m; i++) printf("%c", t[i]);
    putchar(10);
  }
}
