#include <bits/stdc++.h>
using namespace std;
string s;
long long n, m;
long long b[55];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    cin >> s >> m;
    for (long long i = 0; i < m; i++) {
      cin >> b[i];
    }
    vector<vector<long long>> bunch;
    while (true) {
      vector<long long> curr;
      for (long long i = 0; i < m; i++) {
        if (b[i] == 0) {
          curr.push_back(i);
          b[i] = INT_MAX;
        }
      }
      if (curr.empty()) {
        break;
      }
      for (long long i = 0; i < m; i++) {
        if (b[i] == INT_MAX) continue;
        for (auto idx : curr) {
          b[i] -= abs(idx - i);
        }
      }
      bunch.push_back(curr);
    }
    map<char, long long> counts;
    for (auto i : s) {
      counts[i]++;
    }
    auto ptr = counts.rbegin();
    string ans(m, '.');
    for (auto b : bunch) {
      while (ptr->second < b.size()) {
        ptr++;
      }
      for (auto idx : b) {
        ans[idx] = ptr->first;
      }
      ptr++;
    }
    cout << ans << "\n";
  }
  return 0;
}
