#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e9 + 5;
const double eps = 1e-7;
const double PI = acos(-1.0);
inline void debug_vi(vector<int> a) {
  for (long long i = (long long)(0); i < (long long)(a.size()); i++)
    cout << a[i] << " ";
}
inline void debug_vll(vector<long long> a) {
  for (long long i = (long long)(0); i < (long long)(a.size()); i++)
    cout << a[i] << " ";
}
inline void print_case(int tn) { cout << "Case #" << tn << ": "; }
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxpq = priority_queue<T>;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    vector<int> freq(26);
    for (char c : s) {
      freq[c - 'a']++;
    }
    int m;
    cin >> m;
    vector<int> b(m);
    bool used[m];
    int dc = 0;
    memset(used, false, sizeof(used));
    vector<int> zeroes;
    for (long long i = (long long)(0); i < (long long)(m); i++) {
      cin >> b[i];
      if (!b[i]) zeroes.push_back(i);
    }
    string res(m, '-');
    char c = 'z';
    while (dc < m) {
      while (freq[c - 'a'] < zeroes.size()) c--;
      vector<int> newz;
      for (int z : zeroes) {
        dc++;
        res[z] = c;
        used[z] = true;
        for (long long i = (long long)(0); i < (long long)(m); i++) {
          b[i] -= abs(z - i);
        }
      }
      for (long long i = (long long)(0); i < (long long)(m); i++) {
        if (!b[i] && !used[i]) newz.push_back(i);
      }
      swap(zeroes, newz);
      c--;
    }
    cout << res << "\n";
  }
  return 0;
}
