#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int tt = 1;
  cin >> tt;
  for (long long int t = 1; t <= tt; t++) {
    string s;
    cin >> s;
    long long int m;
    cin >> m;
    vector<long long int> arr(m);
    for (long long int i = 0; i <= m - 1; i++) {
      cin >> arr[i];
    }
    map<char, long long int> Map;
    long long int n = s.size();
    for (long long int i = 0; i <= n - 1; i++) {
      Map[s[i]]++;
    }
    vector<char> ans(m, '?');
    long long int cnt = 0;
    char last = '{';
    while (cnt < m) {
      vector<long long int> brr(m, 0), index;
      for (long long int i = 0; i <= m - 1; i++) {
        if (arr[i] == 0) {
          for (long long int j = 0; j <= m - 1; j++) {
            if (arr[j] > 0) {
              brr[j] -= abs(i - j);
            }
          }
          index.push_back(i);
          arr[i] = -1;
        }
      }
      for (long long int i = 0; i <= m - 1; i++) {
        arr[i] += brr[i];
      }
      char c;
      for (auto itr : Map) {
        if (itr.first < last and itr.second >= index.size()) {
          c = itr.first;
        }
      }
      for (auto itr : index) {
        ans[itr] = c;
      }
      last = c;
      cnt += index.size();
    }
    for (long long int i = 0; i <= m - 1; i++) {
      cout << ans[i];
    }
    cout << '\n';
  }
  return 0;
}
