#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
vector<int> ve;
char st[MAXN];
int a[MAXN], sum[MAXN], ans[MAXN];
int main() {
  int t;
  scanf("%d", &t);
  for (int times = 1; times <= t; times++) {
    memset(sum, 0, sizeof(sum));
    memset(ans, 0, sizeof(ans));
    scanf("%s", st);
    int n, len = strlen(st);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 0; i <= len - 1; i++) sum[st[i] - 'a' + 1]++;
    int s = 26;
    while (1) {
      ve.clear();
      for (int i = 1; i <= n; i++) {
        if (ans[i]) continue;
        int res = 0;
        for (int j = 1; j <= n; j++)
          if (ans[j]) res += abs(i - j);
        if (res == a[i]) ve.push_back(i);
      }
      if (!((int)ve.size())) break;
      while (sum[s] < ((int)ve.size())) s--;
      for (int i = 0; i <= ((int)ve.size()) - 1; i++) ans[ve[i]] = s;
      sum[s] -= ((int)ve.size());
      s--;
    }
    for (int i = 1; i <= n; i++) putchar(ans[i] + 'a' - 1);
    puts("");
  }
  return 0;
}
