#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
void __print(long long int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename Th, typename V>
void __print(const pair<Th, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename Th>
void __print(const Th &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void binary_rock() {
  string a;
  cin >> a;
  long long int m;
  cin >> m;
  long long int i, j, k, l;
  vector<long long int> b(m);
  for (i = 0; i < m; i++) cin >> b[i];
  vector<long long int> fre(26);
  for (i = 0; i < 26; i++) fre[i] = 0;
  long long int n = a.size();
  for (i = 0; i < n; i++) {
    fre[a[i] - 'a']++;
  };
  long long int pos = 25;
  string ans = "";
  long long int nikal = 0;
  for (i = 0; i < m; i++) ans.push_back(('-'));
  ;
  ;
  while (1) {
    long long int zero = 0;
    vector<long long int> id;
    for (i = 0; i < m; i++) {
      if (b[i] == 0) id.push_back(i);
    }
    zero = id.size();
    while (1) {
      if (fre[pos] >= zero)
        break;
      else {
        pos--;
      }
    }
    for (i = 0; i < zero; i++) {
      ans[id[i]] = 'a' + pos;
    };
    for (i = 0; i < zero; i++) {
      long long int x = id[i];
      for (j = 0; j < m; j++) {
        if (b[j] == 0) continue;
        b[j] -= abs(x - j);
      }
    };
    for (i = 0; i < zero; i++) {
      b[id[i]] = -1;
    }
    nikal += zero;
    if (nikal >= m) break;
    pos--;
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  clock_t t1 = clock();
  long long int t = 1;
  cin >> t;
  while (t--) {
    binary_rock();
  }
  clock_t t2 = clock();
  return 0;
}
