#include <bits/stdc++.h>
using namespace std;
long long ara[55];
char str[60];
long long cnt[30];
char ans[60];
long long vis[60];
vector<long long> pos;
int main() {
  long long test;
  scanf("%lld", &test);
  while (test--) {
    cin >> str;
    long long sz = strlen(str);
    memset((cnt), (0), sizeof(cnt));
    for (long long i = 0; i < sz; i++) cnt[str[i] - 'a']++;
    long long n;
    scanf("%lld", &n);
    for (long long i = 0; i < n; i++) scanf("%lld", &ara[i]);
    memset((ans), (0), sizeof(ans));
    memset((vis), (0), sizeof(vis));
    long long now = 25;
    for (long long i = 0; i < n; i++) {
      pos.clear();
      for (long long j = 0; j < n; j++) {
        if (vis[j] == 0 and ara[j] == 0) pos.push_back(j);
      }
      for (long long j = 0; j < pos.size(); j++) {
        long long k = pos[j];
        vis[k] = 1;
      }
      for (long long j = 0; j < pos.size(); j++) {
        long long k = pos[j];
        for (long long p = 0; p < n; p++) {
          if (!vis[p]) ara[p] -= abs(k - p);
        }
      }
      for (long long j = now; j >= 0; j--) {
        if (cnt[j] >= pos.size()) {
          for (long long k = 0; k < pos.size(); k++) {
            ans[pos[k]] = (j + 'a');
          }
          now = j - 1;
          break;
        }
      }
    }
    for (long long i = 0; i < n; i++) printf("%c", ans[i]);
    cout << endl;
  }
}
