#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int m, cnt = 0, ele = s.size();
    cin >> m;
    int a[m];
    char h[m];
    multiset<char> ms;
    map<char, int> mp;
    for (int i = 0; i < m; ++i) {
      cin >> a[i];
      if (a[i] == 0) cnt++;
    }
    for (int i = 0; i < s.size(); ++i) {
      ms.insert(s[i]);
      mp[s[i]]++;
    }
    int n = m;
    multiset<char>::iterator it = ms.end();
    it--;
    char flag;
    while (n--) {
      vector<int> v;
      while (1) {
        if (mp[*it] >= cnt)
          break;
        else
          it--;
      }
      for (int i = 0; i < m; ++i) {
        if (a[i] == 0) {
          a[i] = 100000;
          h[i] = (*it);
          mp[*it]--;
          flag = (*it);
          it--;
          ele--;
          v.push_back(i);
        }
      }
      cnt = 0;
      for (int i = 0; i < m; ++i) {
        if (a[i] != 0 && a[i] != 100000) {
          for (int j = 0; j < v.size(); ++j) {
            a[i] -= abs(i - v[j]);
            if (a[i] == 0) cnt++;
          }
        }
      }
      while (1) {
        if (*it == flag && ele >= 0) {
          flag = *it;
          it--;
          ele--;
        } else
          break;
      }
    }
    for (int i = 0; i < m; ++i) {
      cout << h[i];
    }
    cout << endl;
  }
}
