#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
double pi = 3.141592653589793238;
void my_ans_is() {
  string s;
  cin >> s;
  long long n = s.length();
  map<char, long long> ct;
  for (long long i = 0; i < n; i++) ct[s[i]]++;
  long long m;
  cin >> m;
  long long a[m + 1];
  for (long long i = 0; i < m; i++) cin >> a[i];
  char t[m + 10];
  for (long long i = 0; i < m; i++) t[i] = '0';
  for (char c = 'z'; c >= 'a'; c--) {
    vector<long long> z;
    for (long long i = 0; i < m; i++)
      if (a[i] == 0 && t[i] == '0') z.push_back(i);
    if (z.size() <= ct[c]) {
      for (auto j : z) {
        t[j] = c;
        for (long long i = 0; i < m; i++) {
          if (a[i] != 0) a[i] -= abs(i - j);
        }
      }
    }
  }
  for (long long i = 0; i < m; i++) cout << t[i];
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int TT;
  cin >> TT;
  while (TT--) {
    my_ans_is();
  }
  return 0;
}
