#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    string s;
    cin >> s;
    int i, m, ct = 0;
    cin >> m;
    int arr[m];
    for (auto &x : arr) cin >> x;
    int freq[26] = {0};
    for (i = 0; i < s.size(); i++) {
      freq[s[i] - 'a']++;
    }
    int j = 26;
    string res = s;
    res.resize(m);
    while (ct < m) {
      j--;
      int mn = *min_element(arr, arr + m);
      int ans = 0;
      vector<int> vt;
      for (i = 0; i < m; i++)
        if (arr[i] == mn) {
          ans++;
          vt.push_back(i);
        }
      while (freq[j] < ans) j--;
      for (auto i : vt) {
        res[i] = 'a' + j;
        freq[j]--;
        arr[i] = INT_MAX;
        ct++;
        int q = i - 1;
        int g = 1;
        while (q >= 0) {
          arr[q] -= g;
          g++;
          q--;
        }
        g = 1;
        q = i + 1;
        while (q < m) {
          arr[q] -= g;
          g++;
          q++;
        }
      }
    }
    cout << res << "\n";
  }
}
