#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int m;
    cin >> m;
    int b[m];
    for (long long int i = 0; i < (m); i++) cin >> b[i];
    char a[m + 1];
    sort(s.begin(), s.end());
    map<int, int> mp;
    for (long long int i = 0; i < (n); i++) mp[s[i] - 'a']++;
    int j = n - 1;
    while (1) {
      vector<int> v;
      int count = 0;
      for (long long int i = 0; i < (m); i++) {
        if (b[i] == 0) {
          v.push_back(i);
          count++;
        }
      }
      if (count == 0) break;
      if (mp[s[j] - 'a'] < count) {
        j = j - mp[s[j] - 'a'];
        continue;
      }
      int point = j;
      j = j - mp[s[j] - 'a'];
      for (int i = 0; i < m; i++) {
        if (b[i] == 0) {
          a[i] = s[point];
          b[i] = -1;
        } else {
          for (int k = 0; k < v.size(); k++) {
            b[i] -= abs(i - v[k]);
          }
        }
      }
    }
    for (int i = 0; i < m; i++) {
      cout << a[i];
    }
    cout << "\n";
  }
  return 0;
}
