#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
template <typename T>
T gcd(T a, T b) {
  return (b ? __gcd(a, b) : a);
}
template <typename T>
T lcm(T a, T b) {
  return (a * (b / gcd(a, b)));
}
void go() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void solution() {
  string s;
  cin >> s;
  long long b;
  cin >> b;
  vector<long long> a(b);
  map<char, long long> m;
  for (long long i = 0; i < s.length(); ++i) {
    m[s[i]]++;
  }
  long long zero = 0;
  for (long long i = 0; i < b; ++i) {
    cin >> a[i];
    if (a[i] == 0) {
      zero++;
    }
  }
  sort(s.begin(), s.end());
  long long n = s.length();
  vector<char> ans(b);
  for (long long i = n - 1; i >= 0; --i) {
    if (m[s[i]] >= zero) {
      vector<long long> aa;
      for (long long i1 = 0; i1 < b; ++i1) {
        if (a[i1] == 0) {
          aa.push_back(i1);
          a[i1] = -1;
          ans[i1] = s[i];
        }
      }
      zero = 0;
      for (long long i1 = 0; i1 < b; ++i1) {
        if (binary_search(aa.begin(), aa.end(), i1) == 0) {
          for (long long j = 0; j < aa.size(); ++j) {
            if (a[i1] == -1) {
              continue;
            }
            a[i1] -= abs(i1 - aa[j]);
          }
          if (a[i1] == 0) {
            zero++;
          }
        }
      }
      i -= m[s[i]];
      i++;
    }
  }
  for (auto i : ans) {
    cout << i;
  }
  cout << "\n";
}
signed main() {
  go();
  long long t;
  cin >> t;
  while (t--) {
    solution();
  }
  return 0;
}
