#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T& a, T b) {
  a = min(a, b);
}
template <class T>
void chmax(T& a, T b) {
  a = max(a, b);
}
constexpr int INF = 1 << 30;
constexpr long long INFL = 1LL << 60;
constexpr long long MOD = 1000000007;
constexpr long double EPS = 1e-12;
long double PI = acos(-1.0);
string solve2(string s, vector<long long>& b) {
  vector<long long> cnt(26);
  for (char c : s) cnt[c - 'a']++;
  long long c_i = 25;
  long long m = b.size();
  string ans(m, 'X');
  bool update = true;
  while (update) {
    update = false;
    vector<long long> upd_i;
    for (long long i = 0; i < m; i++) {
      if (b[i] == 0 && ans[i] == 'X') upd_i.push_back(i);
    }
    if (upd_i.size() > 0) update = true;
    while (cnt[c_i] < upd_i.size()) --c_i;
    for (auto i : upd_i) ans[i] = 'a' + c_i;
    --c_i;
    for (long long i = 0; i < m; i++) {
      if (b[i] <= 0) continue;
      for (auto j : upd_i) {
        b[i] -= abs(i - j);
      }
    }
  }
  return ans;
}
void solve() {
  long long q;
  cin >> q;
  vector<string> ans;
  for (long long i = 0; i < q; i++) {
    string s;
    long long m;
    cin >> s >> m;
    vector<long long> b(m);
    for (long long j = 0; j < (m); j++) cin >> b[j];
    ans.push_back(solve2(s, b));
  }
  for (auto s : ans) cout << s << endl;
  return;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
}
