#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {0, -1, 0, 1, -1, -1, 1, 1},
          dy[8] = {1, 0, -1, 0, -1, 1, -1, 1};
int a[70], ans[70], vis[70];
char str1[60], str2[60];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(ans, 0, sizeof ans);
    int m;
    scanf("%s", str1);
    int len = strlen(str1);
    for (int i = 0; i < len; i++) ans[str1[i] - 'a']++;
    cin >> m;
    for (int i = 0; i < m; i++) cin >> a[i];
    int now = 25;
    vector<int> ve;
    for (int i = 0; i < m; i++) {
      if (a[i] == 0) ve.push_back(i);
    }
    for (now; now >= 0; now--) {
      if (ve.size() <= ans[now]) {
        for (int i = 0; i < ve.size(); i++) str2[ve[i]] = now + 'a';
        break;
      }
    }
    now--;
    while (now >= 0) {
      vector<int> vt;
      for (int i = 0; i < m; i++) {
        if (a[i] == 0) continue;
        int sum = 0;
        for (int j = 0; j < m; j++) {
          if (a[j] == 0) sum += abs(j - i);
        }
        if (sum == a[i]) {
          vt.push_back(i);
        }
      }
      if (ans[now] >= vt.size()) {
        for (int i = 0; i < vt.size(); i++) {
          a[vt[i]] = 0;
          str2[vt[i]] = now + 'a';
        }
      }
      now--;
    }
    str2[m] = '\0';
    printf("%s\n", str2);
  }
}
