#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long cl(long double a) {
  if (a > (long long)a) {
    return (long long)a + 1;
  } else {
    return (long long)a;
  }
}
long long flr(long double a) { return (long long)a; }
const long long M = 52;
long long arr[M];
string s;
long long m;
void solve() {
  cin >> s;
  cin >> m;
  for (long long i = 0; i < m; i++) cin >> arr[i];
  long long freq[27] = {0};
  long long n = s.length();
  for (long long i = 0; i < n; i++) {
    freq[s[i] - 'a']++;
  }
  vector<long long> ind;
  string ans = "";
  for (long long i = 0; i < m; i++) ans += 'a';
  long long j = 26;
  unordered_map<long long, bool> vis;
  while (j >= 0 && ind.size() != m) {
    vector<long long> cur;
    for (long long i = 0; i < m; i++) {
      if (vis[i]) continue;
      long long diff = 0;
      for (long long k = 0; k < ind.size(); k++) {
        diff += abs(i - ind[k]);
      }
      if (diff == arr[i]) {
        cur.push_back(i);
        vis[i] = true;
      }
    }
    while (freq[j] < cur.size()) j--;
    for (long long i = 0; i < cur.size(); i++) {
      ans[cur[i]] = 'a' + j;
    }
    for (long long i = 0; i < cur.size(); i++) ind.push_back(cur[i]);
    j--;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
}
