#include <bits/stdc++.h>
using namespace std;
void solve(string& s, vector<int>& val, int size) {
  vector<int> letters(26, 0);
  int ssize = s.size();
  for (int i = 0; i < ssize; i++) {
    letters[s[i] - 'a']++;
  }
  sort(s.begin(), s.end());
  int ptr = ssize - 1;
  vector<char> ans(size);
  while (true) {
    int count0 = 0;
    vector<int> zpos;
    for (int i = 0; i < size; i++) {
      if (val[i] == 0) {
        count0++;
        zpos.emplace_back(i);
      }
    }
    if (count0 == 0) break;
    if (letters[s[ptr] - 'a'] < count0) {
      ptr -= letters[s[ptr] - 'a'];
      continue;
    }
    int aux = ptr;
    ptr -= letters[s[ptr] - 'a'];
    for (int i = 0; i < size; i++) {
      if (val[i] == 0) {
        ans[i] = s[aux--];
        val[i] = -1;
      } else {
        for (int& elem : zpos) {
          val[i] -= abs(i - elem);
        }
      }
    }
  }
  for (int i = 0; i < size; i++) {
    cout << ans[i];
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int k;
  for (int i = 0; i < n; i++) {
    string input;
    cin >> input;
    cin >> k;
    vector<int> val(k);
    for (int j = 0; j < k; j++) cin >> val[j];
    solve(input, val, k);
  }
  return 0;
}
