#include <bits/stdc++.h>
using namespace std;
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
const int INF = 1 << 30;
string s;
int m, b[100], ans[100], f[30];
bool done[100];
void slv() {
  int zc = 0, ptr = 'z' - 'a';
  ;
  for (int i = 0; i < (m); i++)
    if (b[i] == 0) zc++;
  while (zc > 0) {
    if (f[ptr] < zc) {
      ptr--;
      continue;
    } else {
      set<int> idx;
      for (int i = 0; i < (m); i++) {
        if (b[i] == 0) {
          ans[i] = ptr;
          idx.insert(i);
          done[i] = 1;
          b[i] = -1;
        }
      }
      for (int i = 0; i < (m); i++) {
        if (idx.find(i) == idx.end()) {
          for (int ind : idx) {
            b[i] -= abs(i - ind);
          }
        }
      }
      ptr--;
    }
    zc = 0;
    for (int i = 0; i < (m); i++)
      if (b[i] == 0) zc++;
  }
  for (int i = 0; i < (m); i++) {
    cout << (char)(ans[i] + 'a');
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> s;
    cin >> m;
    for (int i = 0; i < (m); i++) cin >> b[i];
    memset(f, 0, sizeof(f));
    memset(done, 0, sizeof(done));
    for (int i = 0; i < (s.size()); i++) f[s[i] - 'a']++;
    slv();
  }
  return 0;
}
