#include <bits/stdc++.h>
using namespace std;
string s;
int m, b[55];
int chars[26];
int sol[55];
void solve(std::istream& in, std::ostream& out) {
  int t;
  in >> t;
  while (t--) {
    in >> s;
    in >> m;
    for (int i = (0); i < ((m)); i++) {
      in >> b[i];
    }
    int maxi = -1;
    fill(chars, chars + 26, 0);
    fill(sol, sol + m, -1);
    for (int i = (0); i < ((s.size())); i++) {
      chars[s[i] - 'a']++;
      maxi = max(maxi, s[i] - 'a');
    }
    int rem = m;
    while (rem > 0) {
      int bla = 0;
      for (int j = (0); j < ((m)); j++) {
        if (b[j] == 0 && sol[j] == -1) bla++;
      }
      while (true) {
        if (chars[maxi] >= bla) {
          break;
        }
        maxi--;
      }
      chars[maxi] -= bla;
      for (int j = (0); j < ((m)); j++) {
        if (b[j] == 0 && sol[j] == -1) {
          sol[j] = maxi;
          rem--;
        }
      }
      for (int j = (0); j < ((m)); j++) {
        if (sol[j] != maxi) continue;
        for (int k = (0); k < ((m)); k++) {
          if (k == j || sol[k] == sol[j] || sol[k] != -1) continue;
          b[k] -= abs(k - j);
        }
      }
      maxi--;
    }
    for (int i = (0); i < ((m)); i++) {
      out << (char)(sol[i] + 'a');
    }
    out << '\n';
  }
  return;
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  std::istream& in = cin;
  std::ostream& out = cout;
  (solve(in, out));
  return 0;
}
