#include <bits/stdc++.h>
using namespace std;
string test(string s, vector<int> &h, int l, vector<int> &b) {
  while (l >= 0) {
    if (!h[l]) {
      l--;
      continue;
    }
    string t = s;
    int c = 0;
    int e = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != ' ') continue;
      int d = 0;
      for (int j = 0; j < s.size(); j++) {
        if (s[j] == ' ') continue;
        d += abs(j - i);
      }
      if (d == b[i]) {
        t[i] = char('a' + l);
        c++;
      }
      if (t[i] == ' ') e++;
    }
    if (c <= h[l]) {
      if (!e) return t;
      string res = test(t, h, l - 1, b);
      if (res != "") return res;
    }
    l--;
  }
  return "";
}
int main(int argc, char **argv) {
  long long q, m;
  string s;
  cin >> q;
  while (q--) {
    cin >> s;
    vector<int> h('z' - 'a' + 1);
    for (char c : s) h[c - 'a']++;
    cin >> m;
    vector<int> b(m);
    for (auto &_b : b) cin >> _b;
    string res(m, ' ');
    cout << test(res, h, h.size() - 1, b) << endl;
  }
  return 0;
}
