#include <bits/stdc++.h>
using namespace std;
bool cmp(char a, char b) { return a > b; }
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long ch[27] = {};
    char ans[55] = {};
    string s;
    vector<long long> v;
    long long n, pos, a[55];
    cin >> s >> n;
    long long ac = n;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long i = 0; i < s.size(); i++) {
      ch[s[i] - 'a']++;
    }
    long long tmp = 256;
    while (n) {
      for (long long i = 0; i < ac; i++) {
        if (a[i] == 0) {
          v.push_back(i);
          a[i]--;
        }
      }
      for (long long i = 26; i >= 0; i--) {
        if (ch[i] >= v.size() && i < tmp) {
          tmp = i;
          for (auto x : v) {
            ans[x] = char(i + 'a');
            for (long long j = 0; j < ac; j++) {
              a[j] -= abs(j - x);
            }
            ch[i] = 0;
            n--;
          }
          v.clear();
          break;
        }
      }
    }
    for (long long i = 0; i < ac; i++) {
      cout << ans[i];
    }
    cout << '\n';
  }
}
