#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1},
                            {-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
const long long mod = 998244353;
void solve() {
  string s;
  cin >> s;
  int m;
  cin >> m;
  vector<int> b(m);
  for (long long i = 0; i < (m); i++) {
    cin >> b[i];
  };
  vector<int> cnt(26, 0);
  for (char ch : s) {
    cnt[ch - 'a']++;
  }
  string ans = "";
  for (long long i = 0; i < (m); i++) ans += '#';
  int col = 25;
  while (1) {
    set<int> change;
    for (long long i = 0; i < (m); i++) {
      if (b[i] == 0) {
        change.insert(i);
      }
    }
    if (change.size() == 0) break;
    for (long long i = 0; i < (m); i++) {
      int del = 0;
      if (b[i] > 0) {
        for (int ind : change) {
          del += abs(ind - i);
        }
        b[i] -= del;
      }
    }
    while (col >= 0 && cnt[col] < change.size()) {
      col--;
    }
    if (col < 0 || cnt[col] < change.size()) break;
    assert(col >= 0);
    for (int i : change) {
      assert(b[i] == 0);
      ans[i] = char(col + 'a');
      b[i] = -1;
    }
    col--;
  }
  cout << (ans) << endl;
  ;
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  for (long long T = 1; T <= (t); T++) {
    solve();
  }
  return 0;
}
