#include <bits/stdc++.h>
using namespace std;
using std::cin;
using std::cout;
long long MOD = 998244353;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    map<char, int> map;
    for (int i = 0; i < s.length(); i++) {
      map[s[i]] = map[s[i]] + 1;
    }
    int m;
    cin >> m;
    int arr[m];
    char construct[m];
    for (int i = 0; i < m; i++) cin >> arr[i];
    int count = m;
    while (count > 0) {
      vector<int> zeroes;
      for (int i = 0; i < m; i++) {
        if (arr[i] == 0) {
          zeroes.push_back(i);
        }
      }
      while (prev(map.end())->second < zeroes.size())
        map.erase(prev(map.end()));
      for (int i = 0; i < zeroes.size(); i++) {
        construct[zeroes[i]] = prev(map.end())->first;
        arr[zeroes[i]] = -1;
      }
      map.erase(prev(map.end()));
      for (int i = 0; i < m; i++) {
        for (int c = 0; c < zeroes.size(); c++) {
          arr[i] -= abs(i - zeroes[c]);
        }
      }
      count -= zeroes.size();
    }
    for (int i = 0; i < m; i++) cout << construct[i];
    cout << "\n";
  }
  return 0;
}
