#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int m;
    cin >> m;
    int b[m + 2];
    for (int i = 1; i <= m; i++) {
      cin >> b[i];
    }
    char ans[m + 2];
    sort(s.begin(), s.end());
    map<int, int> mp;
    for (int i = 0; i < n; i++) mp[s[i] - 'a']++;
    int j = n - 1;
    while (true) {
      vector<int> v;
      int count = 0;
      for (int i = 1; i <= m; i++) {
        if (b[i] == 0) {
          count++;
          v.push_back(i);
        }
      }
      if (count == 0) break;
      if (mp[s[j] - 'a'] < count) {
        j = j - mp[s[j] - 'a'];
        continue;
      }
      int flag = j;
      j = j - mp[s[j] - 'a'];
      for (int i = 1; i <= m; i++) {
        if (b[i] == 0) {
          ans[i] = s[flag--];
          b[i] = -1;
        } else {
          for (int k = 0; k < v.size(); k++) {
            b[i] = b[i] - abs(i - v[k]);
          }
        }
      }
    }
    for (int i = 1; i <= m; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
}
