#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
using namespace std::chrono;
using namespace std;
long long mul(long long a, long long b, long long m = 1000000007) {
  long long res = 0;
  a = a % m;
  while (b > 0) {
    if (b % 2 == 1) res = (res + a) % m;
    a = (a * 2) % m;
    b /= 2;
  }
  return res % m;
}
long long expMod(long long a, long long b, long long m = 1000000007) {
  long long x = 1, y = a;
  while (b) {
    if (b % 2 == 1) {
      x = mul(x, y, m);
    }
    y = mul(y, y, m);
    b = b / 2;
  }
  return x;
}
long long pw(long long a, long long b) {
  long long c = 1, m = a;
  while (b) {
    if (b & 1) c = (c * m);
    m = (m * m);
    b /= 2;
  }
  return c;
}
long long pwmd(long long a, long long b) {
  long long c = 1, m = a;
  while (b) {
    if (b & 1) c = (c * m) % 1000000007;
    m = (m * m) % 1000000007;
    b /= 2;
  }
  return c;
}
long long mmi(long long a) {
  long long inverse = pwmd(a, 1000000007 - 2);
  return inverse;
}
long long nCrModp(long long n, long long r) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i < n + 1; ++i)
    for (long long j = min(i, r); j >= 1; --j)
      C[j] = (C[j] + C[j - 1]) % 1000000007;
  return C[r];
}
int my_log(long long n, int b) {
  long long i = 1;
  int ans = 0;
  while (1) {
    if (i > n) {
      ans--;
      break;
    }
    if (i == n) break;
    i *= b;
    ans++;
  }
  return ans;
}
inline bool kthbit(long long n, int k) { return (n >> k) & 1; }
inline long long setkthbit(long long n, int k) { return n | (1ll << k); }
inline long long unsetkthbit(long long n, int k) { return n & ~(1ll << k); }
inline long long flipkthbit(long long n, int k) { return n ^ (1ll << k); }
bool isfun(char ans[], long long N) {
  for (long long i = 0; i < N; ++i) {
    if (ans[i] == '#') return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long T, M, x;
  cin >> T;
  while (T--) {
    map<char, long long> mp;
    string str;
    cin >> str;
    for (long long i = 0; i < str.length(); ++i) {
      mp[str[i]]++;
    }
    cin >> M;
    vector<long long> A;
    for (long long i = 0; i < M; ++i) {
      cin >> x;
      A.push_back(x);
    }
    vector<long long> st;
    bool vis[M];
    for (long long i = 0; i < M; ++i) {
      vis[i] = false;
    }
    char ans[M];
    for (long long i = 0; i < M; ++i) {
      ans[i] = '#';
    }
    char arr[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    long long pos = 25;
    while (!isfun(ans, M)) {
      for (long long i = 0; i < M; ++i) {
        if (A[i] == 0 && !vis[i]) {
          vis[i] = true;
          st.push_back(i + 1);
        }
      }
      while (pos >= 0) {
        if (mp.find(arr[pos]) != mp.end() && mp[arr[pos]] >= st.size()) {
          for (long long i = 0; i < st.size(); ++i) {
            ans[st[i] - 1] = arr[pos];
          }
          pos--;
          break;
        }
        pos--;
      }
      if (isfun(ans, M) || st.size() == 0) break;
      while (st.size() != 0) {
        long long tp = st[st.size() - 1];
        st.pop_back();
        for (long long i = 0; i < M; ++i) {
          if (!vis[i]) {
            A[i] = A[i] - abs(tp - i - 1);
          }
        }
      }
    }
    for (long long i = 0; i < M; ++i) {
      cout << ans[i];
    }
    cout << "\n";
  }
}
