Problem: G: Code Art Online

Code Art Online (CAO) is an online RPG that advances adventures by solving various problems by programming. Since CAO was the world's first game that realized a virtual reality space, it was sold out while it was very popular, and users who purchased the game should enjoy this world. However, players who dive into the game are told a terrifying decree by the gamemaster.

"Unless some of you players solve the last problem of the last dungeon, you can't get out of this virtual space. And in this world, WA and TLE / RE mean death in the real world. I want you to start the problem with your heart. "

You are one of the CAO players, and you are doing your best to capture the game in order to clear this game and return to the real world. One day, you face the following problems.

This time, a party was formed with n members to capture the new dungeon. You are one of the parties. In order to enter the dungeon that you are about to capture, you must pass through a hole that can be seen from the cliff. If you can pass through the hole safely, you can enter the dungeon, but if you can not enter the hole and touch other parts, death is waiting. Furthermore, if someone passes through one hole, that hole will close, so each person must enter a separate hole.

Holes and people are considered on a two-dimensional plane. The shape of the hole is a circle of various sizes, as shown in Fig. G-1. In the input, the length of the radius is given.

<image>
---
Figure G-1: Hole shape

As shown in Fig. G-2, the human shape is given as a polygonal cross section of the human (not necessarily convex). In the input, the vertices are given counterclockwise to represent the shape of the polygon. It can be assumed that any three points of a polygon do not line up on a straight line. Furthermore, it is assumed that polygonal line segments do not intersect each other except for the purpose of forming vertices. It may rotate freely to pass through the hole (however, rotation in the z-axis direction is prohibited). It is assumed that the vertices of a polygon representing a person can pass through the hole even if it is on the circumference of the hole.

<image>
---
Figure G-2: Human shape

You, who have the highest algorithm skills in the party, decided to solve the decision problem of whether everyone can pass through the hole safely. If you can pass it safely, indicate who should pass which hole.

* You will not die in this contest, but if you make a mistake, please solve it with the intention of dying.

Input

On the first line, the integer n (1 <= n <= 100), which represents the number of holes, and the integer m (1 <= m <= n), which represents the number of parties, are entered separated by spaces.

In the next line, n integers ri (1 <= ri <= 1000) representing the radius of the hole are entered, separated by spaces. These holes are counted as the 1st hole, the 2nd hole, ..., and the nth hole in the order of input.

Then, information on the shape of m people is input. For the information of one person, the number of vertices p (3 <= p <= 100) of the polygon is first input to the first line. In the following line p, the coordinates of the vertices of the polygon are given counterclockwise. Integers xi, yi (-1000 <= xi, yi <= 1000) representing one vertex are entered in each line, separated by spaces. People are counted as the 1st person, the 2nd person, ..., and the mth person in the order of input.

Output

Output the number of hole that the person with i (1 <= i <= m) should enter. On the i-line, output the number of the hole that the person i should pass through.

If there are multiple paths, output the smallest path in lexicographical order. When there are two sequences A = {a1, a2, ..., am} and B = {b1, b2, ..., bm}, if A is smaller than B in lexicographical order, ai is bi. For the first i that is different, we say when ai is smaller than bi.

If no way is found, output one line as "NG". Don't forget to print a newline at the end.

Sample Input 1


3 3
25 100 10
8
-10 0
-twenty two
0 10
twenty two
10 0
twenty two
0 -10
-twenty two
Four
30 0
50 0
50 40
30 40
3
30 -10
45 -70
60 -10


Sample Output 1


3
1
2


Sample Input 2


4 3
25 15 15 30
Five
0 0
10 0
20 10
0 20
-20 10
3
20 0
40 0
30 10
3
-50 0
-30 0
-40 10


Sample Output 2


1
2
3


Sample Input 3


twenty two
1 30
Four
0 0
10 0
10 10
0 10
3
5 5
20 20
5 20


Sample Output 3


NG






Example

Input

3 3
25 100 10
8
-10 0
-2 2
0 10
2 2
10 0
2 -2
0 -10
-2 -2
4
30 0
50 0
50 40
30 40
3
30 -10
45 -70
60 -10


Output

3
1
2

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}
const int MAX_N=101;
 
int N,M;
int RS[101];
vector<pii>  v;
double XS[MAX_N],YS[MAX_N];
double MANR[MAX_N];
 
double solve(double xs[MAX_N],double ys[MAX_N],int n){
  // 球の中心座標
  double cx=0,cy=0;
  // 初期中心座標を決定
  for(int i=0;i<n;i++)cx+=xs[i],cy+=ys[i];
  cx/=n,cy/=n;
  // iterate回数
  const int ITE_MAX=50;
  double co=0.5;
  // このloopで移動係数を変更
  for(int o=0;o<50;o++){
    // この回数最も距離が遠い点のベクトルを使って移動
    for(int iter=0;iter<ITE_MAX;iter++){
      int idx=-1;
      double max_dist=-1;
      double d;
      // 最大距離とその点のindexを求める
      for(int j=0;j<n;j++){
        d=sqrt(pow(xs[j]-cx,2)+pow(ys[j]-cy,2));
        if(max_dist<d)max_dist=d,idx=j;
      }
      // 現在地点から移動
      double dx=xs[idx]-cx,dy=ys[idx]-cy;
      cx+=dx*co;
      cy+=dy*co;
    }
    co/=2;
  }
  // 最大距離を計算
  double max_dist=-1;
  for(int j=0;j<n;j++){
    double d=sqrt(pow(xs[j]-cx,2)+pow(ys[j]-cy,2));
    max_dist=max(max_dist,d);
  }
  return max_dist;
}
 
const int MAX_V = 1000;
const int INF = 100000000;
 
// グラフのリスト表現
vector<int> G[MAX_V];
// マッチングのペア
int match[MAX_V];
// dfsですでに調べたかどうかのフラグ
bool used[MAX_V];
// uとvを結ぶ辺をグラフに追加
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}
bool isOk[201];
 
// 増加パスをdfsで探す
bool dfs(int v){
  used[v] = true;
  for(int i = 0; i < (int)G[v].size(); i++){
    int u = G[v][i],w = match[u];
    if( !isOk[u] && !isOk[w] ){
      if(w < 0 || (!used[w] && dfs(w))){
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
  }
  return false;
}
 
// 二部グラフの最大マッチングを求める
int bipartite_matching(int V){
  int res = 0;
  memset(match,-1,sizeof(match));
  for(int v = 0; v < V; v++){
    if(match[v] < 0&&!isOk[v]){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}
 
int ans[101];
int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++)cin>>RS[i];
  for(int i=0;i<M;i++){
    int p;
    cin>>p;
    for(int j=0;j<p;j++)cin>>XS[j]>>YS[j];
    MANR[i]=solve(XS,YS,p);
  }
  bool no=false;
  for(int j=0;j<M;j++)
    for(int i=0;i<N;i++)
      if(EQ(RS[i],MANR[j])||RS[i]>MANR[j])
        add_edge(j,i+M);
  // そのグラフに対して、辞書順の二部マッチング
  for(int l=0;l<M;l++){
    no=true;
    // MANRとRSを比較し、MANRがRSより小さければエッジを貼る
    if(isOk[l])continue;
    for(int k=0;k<N;k++){
      // l-k間にエッジを貼ると仮定してすすめる
      // よってlとkにはエッジを貼らない状態でマッチングを調べる
      if(isOk[k+M])continue;
      if(!(EQ(RS[k],MANR[l])||RS[k]>MANR[l]))continue;
      isOk[k+M]=isOk[l]=true;
      // もし二部マッチングで得られた値がM-l-1であれば、この場所の貼り方を確定
      if(bipartite_matching(N+M)==M-l-1){
        ans[l]=k+1;
        no=false;
        break;
      }
      else isOk[k+M]=isOk[l]=false;
    }
    if(no)break;
  }
  if(no)cout<<"NG"<<endl;
  else for(int i=0;i<M;i++)cout<<ans[i]<<endl;
  return 0;
}