#include <bits/stdc++.h>
using namespace std;
void LOOPCHK(int a[], int n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tt = 1;
  cin >> tt;
  for (int cse = 1; cse <= tt; cse++) {
    int i, j, k, l, m, n, x = 0, y = 0, z = 0, ans = 0, sum = 0, b[51],
                          res[51] = {0}, typeused[27] = {0}, ihave[27] = {0},
                          soja[51], ulta[51];
    string s, t;
    cin >> s >> n;
    memset(soja, 0, sizeof(soja));
    memset(ulta, 0, sizeof(ulta));
    for (int i = 0; i < s.size(); i++) ihave[s[i] - 'a']++;
    for (int i = 0; i < n; i++) cin >> b[i];
    while (x < n) {
      y++;
      soja[0] = ulta[n - 1] = x = 0;
      for (int i = 0; i < n; i++) {
        if (x) soja[i] = soja[i - 1] + x;
        if (res[i]) x++;
      }
      x = 0;
      for (int i = n - 1; i >= 0; i--) {
        if (x) ulta[i] = ulta[i + 1] + x;
        if (res[i]) x++;
        if (res[i] == 0 && soja[i] + ulta[i] == b[i]) {
          res[i] = y;
          typeused[y]++;
        }
      }
    }
    char now = 'z';
    map<int, char> mp;
    x = 1;
    for (int i = 1; i < 27 && typeused[i] > 0; i++) {
      while (now > 'a' && ihave[now - 'a'] < typeused[i]) now--;
      mp[i] = now--;
    }
    for (int i = 0; i < n; i++) cout << mp[res[i]];
    cout << "\n";
    ;
  }
  return 0;
}
