#include <bits/stdc++.h>
using namespace std;
long long int modu(long long int i, long long int j) {
  if (i > j) {
    return i - j;
  } else {
    return j - i;
  }
}
void solve() {
  string s;
  cin >> s;
  long long int m;
  long long int ch[30] = {0};
  long long int a[55], b[55] = {0};
  cin >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (long long int i = 0; i < s.size(); i++) {
    ch[s.at(i) - 'a']++;
  }
  long long int ind = 25;
  char ans[55];
  vector<long long int> inde;
  while (true) {
    inde.clear();
    long long int same = 0;
    for (long long int i = 0; i < m; i++) {
      if (a[i] == b[i]) {
        same++;
        inde.push_back(i);
      }
    }
    if (same == 0) {
      break;
    }
    while (ch[ind] < same) {
      ind--;
    }
    for (long long int i = 0; i < inde.size(); i++) {
      ans[inde[i]] = (char)('a' + ind);
      for (long long int j = 0; j < m; j++) {
        if (b[j] < a[j]) {
          b[j] += modu(inde[i], j);
        }
      }
      b[inde[i]] = INT_MAX;
    }
    ind--;
  }
  for (long long int i = 0; i < m; i++) {
    cout << ans[i];
  }
  cout << "\n";
}
int32_t main() {
  long long int t = 1;
  scanf("%lld", &t);
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  cerr << "\n"
       << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
