#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  int m;
  cin >> s >> m;
  vector<int> cnt(26);
  for (char c : s) {
    cnt[c - 'a']++;
  }
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<char> str(m);
  vector<int> dist(m);
  set<int> pos, filled;
  int largest = 26;
  while (filled.size() < m) {
    pos.clear();
    int amt = 0;
    for (int i = 0; i < m; i++) {
      if (dist[i] == b[i] && !filled.count(i)) {
        amt++;
        pos.insert(i);
        filled.insert(i);
      }
    }
    for (int i = 0; i < m; i++) {
      if (!filled.count(i)) {
        for (int j : pos) {
          dist[i] += abs(j - i);
        }
      }
    }
    for (int i = largest - 1; i >= 0; i--) {
      if (cnt[i] >= amt) {
        largest = i;
        break;
      }
    }
    for (int i : pos) {
      str[i] = 'a' + largest;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << str[i];
  }
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) solve();
  return 0;
}
