#include <bits/stdc++.h>
using namespace std;
void solve() {
  string input_str;
  int n, val;
  cin >> input_str >> n;
  vector<int> letter_cnt(26);
  for (auto ch : input_str) letter_cnt[ch - 'a']++;
  reverse(letter_cnt.begin(), letter_cnt.end());
  vector<int> input_arr(n);
  for (int i = 0; i < n; i++) cin >> input_arr[i];
  int letter_idx = 0, remaining = n;
  string ans_str(n, '0');
  while (true) {
    int cur_zero_cnt = 0;
    vector<int> zero_vec;
    for (int i = 0; i < n; i++)
      if (input_arr[i] == 0) cur_zero_cnt++;
    if (not remaining) break;
    remaining -= cur_zero_cnt;
    while (letter_cnt[letter_idx] < cur_zero_cnt) letter_idx++;
    for (int i = 0; i < n; i++)
      if (input_arr[i] == 0) ans_str[i] = 'z' - letter_idx;
    vector<int> temp(input_arr);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (input_arr[j] == 0) temp[i] -= abs(i - j);
    for (int i = 0; i < n; i++)
      if (input_arr[i] == 0) temp[i] = -1;
    input_arr = temp;
    letter_idx++;
    if (letter_idx >= 26) break;
  }
  cout << ans_str << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int test_cnt;
  cin >> test_cnt;
  while (test_cnt--) solve();
  return 0;
}
