#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
struct Point {
  int x, y;
  Point() {}
  Point(int x, int y) : x(x), y(y) {}
  long double abs() const { return hypot(x, y); }
  long double arg() const { return atan2(y, x); }
  Point operator*(double o) const { return Point(x * o, y * o); }
  Point operator+(const Point& o) const { return Point(x + o.x, y + o.y); }
  Point operator-(const Point& o) const { return Point(x - o.x, y - o.y); }
  Point operator/(double o) const { return Point(x / o, y / o); }
  bool operator<(const Point& o) const {
    return x < o.x - 1e-9 || (x < o.x + 1e-9 && y < o.y - 1e-9);
  }
  friend bool operator==(const Point& r1, const Point& r2) {
    return r1.x == r2.x && r1.y == r2.y;
  }
  int cross(Point b) const { return x * b.y - b.x * y; }
  void readin() { scanf("%d%d", &x, &y); }
  void pp() { printf("%d %d\n", x, y); }
} a[6135], b[6135];
int r[6135];
void cal(vector<int> A, vector<int> B) {
  if (A.size() == 1) {
    if (!debug)
      for (int z : B) printf("%d %d\n", z, A[0]);
    return;
  }
  if (B.size() == 1) {
    if (!debug)
      for (int z : A) printf("%d %d\n", B[0], z);
    return;
  }
  assert(A.size() > 1 && B.size() > 1);
  int mxR = 0, tar = -1;
  for (int z : B)
    if (mxR < r[z]) {
      tar = z;
      mxR = r[z];
    }
  vector<pair<long double, int>> vp;
  for (int z : A) {
    vp.push_back({(a[z] - b[tar]).arg(), z + m});
  }
  for (int z : B)
    if (z != tar) {
      vp.push_back({(b[z] - b[tar]).arg(), z});
    }
  sort(vp.begin(), vp.end());
  int N = vp.size(), S = 0;
  for (int i = 0, j = -1; i < N; i++) {
    j = max(i, j);
    if (i == j) {
      S += 1 - r[vp[i].second];
      j++;
    }
    Point cur = vp[i].second <= m ? b[vp[i].second] : a[vp[i].second - m];
    cur = cur - b[tar];
    while (1) {
      int id = vp[j % N].second;
      Point tt = id <= m ? b[id] : a[id - m];
      tt = tt - b[tar];
      if (tt.cross(cur) < 0) {
        S += 1 - r[id];
        j++;
      } else
        break;
    }
    if (S >= 1 && S <= mxR - 1) {
      r[tar] = S;
      vector<int> ta, tb;
      tb.push_back(tar);
      for (int z = i; z < j; z++) {
        int id = vp[z % N].second;
        if (id <= m)
          tb.push_back(id);
        else
          ta.push_back(id - m);
      }
      cal(ta, tb);
      r[tar] = mxR - S;
      ta.clear();
      tb.clear();
      tb.push_back(tar);
      for (int z = j;; z++) {
        if (z % N == i) break;
        int id = vp[z % N].second;
        if (id <= m)
          tb.push_back(id);
        else
          ta.push_back(id - m);
      }
      cal(ta, tb);
      break;
    }
    S -= 1 - r[vp[i].second];
  }
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%d", r + i);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) r[m + i] = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) a[i].readin();
  for (int(j) = 1; (j) <= (int)(m); (j)++) b[j].readin();
  vector<int> A, B;
  for (int(i) = 1; (i) <= (int)(n); (i)++) A.push_back(i);
  for (int(j) = 1; (j) <= (int)(m); (j)++) B.push_back(j);
  if (!debug) puts("YES");
  cal(A, B);
}
int main() {
  int t = 1;
  scanf("%d", &t);
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
