#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.size(), k;
  cin >> k;
  int b[55];
  for (int i = 0; i < k; i++) cin >> b[i];
  int freq[26];
  memset(freq, 0, sizeof(freq));
  for (int i = 0; i < n; i++) freq[s[i] - 'a']++;
  string sol(k, ' ');
  int cur = 25;
  while (true) {
    int zero_count = 0;
    vector<int> pos;
    for (int i = 0; i < k; i++) {
      if (b[i] == 0) {
        pos.push_back(i);
        zero_count++;
      }
    }
    if (pos.size() == 0) break;
    int charIndex = -1;
    while (cur >= 0) {
      if (freq[cur] >= zero_count) {
        freq[cur] -= zero_count;
        charIndex = cur;
        break;
      }
      cur--;
    }
    for (int i = 0; i < pos.size(); i++) {
      sol[pos[i]] = (char)(97 + charIndex);
    }
    cur--;
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < pos.size(); j++) {
        if (i != pos[j] && b[i] > 0) b[i] -= abs(i - pos[j]);
      }
    }
    for (int i = 0; i < pos.size(); i++) b[pos[i]] = -1;
    pos.clear();
  }
  cout << sol << endl;
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
