#include <bits/stdc++.h>
using namespace std;
int a[55];
int aa[55];
int vis[55];
map<char, int> letters;
vector<char> let;
char ans[55];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    let.clear();
    letters.clear();
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (char c : s) letters[c]++;
    for (auto i : letters) let.push_back(i.first);
    reverse(let.begin(), let.end());
    for (int i = 0; i < n; i++) {
      bool bad = 0;
      for (int j = 0; j < n; j++) {
        aa[j] = a[j];
        vis[j] = 0;
      }
      int cur_let = i;
      bool found = 1;
      while (found) {
        found = 0;
        int cnt = 0;
        for (int j = 0; j < n; j++) {
          if (!vis[j] && !aa[j]) {
            vis[j] = 1;
            cnt++;
          }
        }
        if (cnt == 0) break;
        while (letters[let[cur_let]] < cnt && cur_let < let.size()) {
          cur_let++;
        }
        for (int j = 0; j < n; j++) {
          if (vis[j] == 1) {
            found = 1;
            if (cur_let >= let.size()) bad = 1;
            vis[j] = 2;
            ans[j] = let[cur_let];
            for (int k = 0; k < n; k++) {
              if (aa[k]) {
                aa[k] -= abs(k - j);
              }
            }
          }
        }
        cur_let++;
        for (int j = 0; j < n; j++) {
          if (aa[j] < 0) bad = 1;
        }
      }
      if (!bad) {
        for (int i = 0; i < n; i++) cout << ans[i];
        cout << "\n";
        break;
      }
    }
  }
  return 0;
}
