#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int m;
    cin >> m;
    vector<int> b(m), idx;
    int n_zeroes = 0;
    for (int i = 0; i < m; ++i) {
      cin >> b[i];
      if (b[i] == 0) {
        ++n_zeroes;
        idx.push_back(i);
      }
    }
    sort(s.begin(), s.end());
    map<char, int> cnt;
    for (char c : s) {
      ++cnt[c];
    }
    vector<char> ans(m);
    int len = 0;
    for (;;) {
      char who = '\0';
      if (n_zeroes == 1) {
        who = s.back();
        while (s.back() == who) {
          s.pop_back();
        }
      } else {
        while (cnt[s.back()] < n_zeroes) {
          s.pop_back();
        }
        who = s.back();
        while (s.back() == who) {
          s.pop_back();
        }
      }
      assert(who != '\0');
      for (int id : idx) {
        ans[id] = who;
      }
      len += idx.size();
      if (len == m) {
        break;
      }
      vector<int> new_idx;
      n_zeroes = 0;
      for (int i = 0; i < m; ++i) {
        for (int j : idx) {
          if (b[i] > 0) {
            b[i] -= abs(i - j);
            if (b[i] == 0) {
              new_idx.push_back(i);
              ++n_zeroes;
            }
          }
        }
      }
      idx = new_idx;
    }
    for (auto e : ans) {
      cout << e;
    }
    cout << '\n';
  }
  return 0;
}
