#include <bits/stdc++.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
string s;
int n;
vector<int> v;
string solve();
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> s >> n;
    v.resize(n);
    for (auto &i : v) cin >> i;
    cout << solve() << '\n';
  }
  return 0;
}
string solve() {
  string rez;
  rez.resize(n, 0);
  map<char, int> ma;
  ma.clear();
  for (auto i : s) ma[i]++;
  vector<int> vz;
  vz.clear();
  for (int t = 0; t < n; t++)
    if (!v[t]) vz.push_back(t);
  char ch = 'z';
  while (!vz.empty()) {
    while (ma[ch] < vz.size()) ch--;
    for (auto i : vz) rez[i] = ch;
    for (auto i : vz) {
      for (int t = 0; t < n; t++)
        if (v[t] && !rez[t]) v[t] -= abs(i - t);
    }
    vz.clear();
    for (int t = 0; t < n; t++)
      if (!v[t] && rez[t] == 0) vz.push_back(t);
    ch--;
  }
  return rez;
}
