#include <bits/stdc++.h>
using namespace std;
long long fastpower(long long b, long long p) {
  long long k = p % 2 ? b : 1;
  return p == 0 ? 1 : k * (fastpower(b * b, p / 2));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t1;
  cin >> t1;
  while (t1--) {
    string s;
    cin >> s;
    int m;
    cin >> m;
    int b[m];
    for (int i = 0; i < m; i++) cin >> b[i];
    vector<vector<int>> groups;
    while (1) {
      vector<int> pos;
      for (int i = 0; i < m; i++) {
        if (b[i] == 0) pos.push_back(i);
      }
      if (pos.empty()) break;
      groups.push_back(pos);
      for (int i = 0; i < m; i++) {
        if (b[i] == 0)
          b[i] = INT_MAX;
        else {
          for (auto x : pos) b[i] -= abs(i - x);
        }
      }
    }
    map<char, int> mp;
    for (int i = 0; i < s.length(); i++) mp[s[i]]++;
    auto j = mp.rbegin();
    string t(m, '?');
    for (auto i : groups) {
      while (j->second < i.size()) j++;
      for (auto x : i) t[x] = j->first;
      j++;
    }
    cout << t << "\n";
  }
}
