Problem:
 Score : 200 points    Problem Statement There are N students and M checkpoints on the xy -plane. The coordinates of the i -th student (1 \leq i \leq N) is (a_i,b_i) , and the coordinates of the checkpoint numbered j  (1 \leq j \leq M) is (c_j,d_j) . When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance . The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2| . Here, |x| denotes the absolute value of x . If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to?      Constraints  1 \leq N,M \leq 50  -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8  All input values are integers.         Input The input is given from Standard Input in the following format:  N  M  a_1  b_1  :  a_N  b_N  c_1  d_1  :  c_M  d_M       Output Print N lines. The i -th line (1 \leq i \leq N) should contain the index of the checkpoint for the i -th student to go.        Sample Input 1 2 2
2 0
0 0
-1 0
1 0      Sample Output 1 2
1  The Manhattan distance between the first student and each checkpoint is:   For checkpoint 1 : |2-(-1)|+|0-0|=3  For checkpoint 2 : |2-1|+|0-0|=1   The nearest checkpoint is checkpoint 2 . Thus, the first line in the output should contain 2 .  The Manhattan distance between the second student and each checkpoint is:   For checkpoint 1 : |0-(-1)|+|0-0|=1  For checkpoint 2 : |0-1|+|0-0|=1   When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1 .       Sample Input 2 3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5      Sample Output 2 3
1
2  There can be multiple checkpoints at the same coordinates.       Sample Input 3 5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000      Sample Output 3 5
4
3
2
1

Solution (Python):
import math

N, M = map(int, raw_input().split())
a = []
for i in range(N+M):
    a.append(map(int, raw_input().split()))

b=[]

def mhtn(a,b,c,d):
    return 

for i in range(N):
    best=4*10e8
    num=0
    for j in range(M):
        x=math.fabs(a[i][0]-a[N+j][0])+math.fabs(a[i][1]-a[N+j][1])
        
        if(best>x):
            best=x
            num=j+1
    b.append(num)

for i in b:
    print i

Solution (Python):
n, m = map(int, input().split())

students = []
for i in range(n):
    axis = [int(x) for x in input().split()]
    students.append(axis)

checkpoints = []
for i in range(m):
    axis = [int(x) for x in input().split()]
    checkpoints.append(axis)

ans = []
for s_x, s_y in students:
    distances = []
    for c_x, c_y in checkpoints:
        distances.append(abs(s_x - c_x) + abs(s_y - c_y))
    i_c = 0
    i_d = 4 * 10 ** 8 + 1
    for cnt, distance in enumerate(distances, 1):
        if i_d > distance:
            i_d = distance
            i_c = cnt
        else:
            pass
    ans.append(i_c)

for i in ans:
    print(i)

Solution (Python):
N, M = map(int, input().split())
a = {}
b = {}
c = {}
d = {} 

for i in range(N):
    a[i],b[i] = map(int, input().split())
for i in range(M):
    c[i],d[i] = map(int, input().split())

for i in range(N):
    m = 100000000000
    index = 0
    for j in range(M):
        tmp = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if tmp < m:
            m = tmp 
            index = j
    print(index + 1)

Solution (Python):
N, M = list(map(int, input().split()))

a = []
c = []
for i in range(0, N + M):
    s = list(map(int, input().split()))
    if  i < N:
        a.append(s)
    else:
        c.append(s)

for i in range(0, N):
    min_idx = 0
    min_dis = 999999999999
    for j in range(0, M):
        dis = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if min_dis > dis:
            min_dis = dis
            min_idx = j + 1
    print(str(min_idx))

Solution (Python):
N,M = map(int,input().split())
A = []
for n in range(N):
	a,b = map(int,input().split())
	A.append([a,b])
B = []
for m in range(M):
	l = list(map(int,input().split()))
	l.append(m)
	B.append(l)

for a in A:
	R = min([abs(B[i][0] - a[0]) + abs(B[i][1] - a[1]) for i in range(M)])
	B2 = [b for b in B if abs(b[0] - a[0]) + abs(b[1] - a[1]) == R]
	print(min([b[2] for b in B2]) + 1)

Solution (Python):



def solve(s_pp, p_pp):
    p_nums = []
    for x, y in s_pp:
        distance = []
        for xx, yy in p_pp:
            n = abs(x - xx) + abs(y - yy)
            distance.append(n)
        min_distance_idx = distance.index(min(distance))
        p_nums.append(min_distance_idx + 1)
    return p_nums


def main():
    students, points = [int(e) for e in input().split()]
    students_ps = []
    points_ps = []

    for _ in range(students):
        x, y = [int(e) for e in input().split()]
        students_ps.append([x, y])
    for _ in range(points):
        x, y = [int(e) for e in input().split()]
        points_ps.append([x, y])
    
    for answer in solve(students_ps, points_ps):
        print(answer)


main()

Solution (Python):
def mlen(n,m):
	global M,s,c
	return abs(s[n][0] - c[m][0]) + abs(s[n][1] - c[m][1])

N,M = [int(i) for i in input().split()]
s=[] 
c=[] 
for i in range(N):
	x,y=[int(i) for i in input().split()]
	s.append([x,y])
for i in range(M):
	x,y=[int(i) for i in input().split()]
	c.append([x,y])
for i in range(N):
	pos = 0
	min = mlen(i,0)
	for j in range(1,M):
		if mlen(i,j) < min:
			pos = j
			min = mlen(i,j)
	print(pos+1)

Solution (Python):


n,m=map(int,input().split())

a=[0 for i in range(n+1)]
b=[0 for i in range(n+1)]
c=[0 for i in range(m+1)]
d=[0 for i in range(m+1)]



for i in range(1,n+1):
    a[i],b[i]=map(int,input().split())
for j in range(1,m+1):
    c[j],d[j]=map(int,input().split())

for i in range(1,n+1):
    min=abs(a[i]-c[1])+abs(b[i]-d[1])+1
    for j in range(1,m+1):
        dis = abs(a[i]-c[j])+abs(b[i]-d[j])
        if dis<min: min=dis ; ans=j
    print(ans)

Solution (Python):


import collections


Point = collections.namedtuple("Point", "x y idx")


def manhattan_dist(p1, p2):
    return abs(p1.x - p2.x) + abs(p1.y - p2.y)


def find_res_point(st, ps):
    def key(p):
        return (manhattan_dist(st, p), p.idx)
    return min(ps, key=key)


def solve(sts, ps):
    return (find_res_point(st, ps) for st in sts)


def main():
    n, m = (int(x) for x in input().split())
    sts = []
    for i in range(n):
        a, b = (int(x) for x in input().split())
        sts.append(Point(a, b, i + 1))
    ps = []
    for j in range(m):
        c, d = (int(x) for x in input().split())
        ps.append(Point(c, d, j + 1))
    for p in solve(sts, ps):
        print(p.idx)


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, raw_input().split())
S = [map(int, raw_input().split()) for _ in xrange(N)]
P = [map(int, raw_input().split()) for _ in xrange(M)]
C = []

def dist(s, p):
	return abs(s[0]-p[0])+abs(s[1]-p[1])

for s in S:
	min_dist = dist(s, P[0])
	min_p = 0
	for i in xrange(1, M):
		d = dist(s, P[i])
		if  d < min_dist:
			min_dist = d
			min_p = i
	C.append(min_p+1)
for c in C:
	print c

Solution (Python):
def main():
    N, M = map(int, input().split())
    a, b = [0] * N, [0] * N
    for i in range(N):
        a[i], b[i] = map(int, input().split())
    c, d = [0] * M, [0] * M
    for i in range(M):
        c[i], d[i] = map(int, input().split())
    for i in range(N):
        min_d = 2 * 10 ** 8
        min_d_j = 0
        for j in range(M):
            md = abs(a[i] - c[j]) + abs(b[i] - d[j])
            if md < min_d:
                min_d = md
                min_d_j = j
        print(min_d_j + 1)

if __name__ == '__main__':
    main()

Solution (Python):
[n,m]=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
d=[]
for _ in range(n):
  [x,y]=[int(i) for i in input().split()]
  a.append(x)
  b.append(y)
for _ in range(m):
  [x,y]=[int(i) for i in input().split()]
  c.append(x)
  d.append(y)

e=[[0 for j in range(m)] for i in range(n)]
for i in range(n):
  for j in range(m):
    e[i][j]=abs(a[i]-c[j])+abs(b[i]-d[j])
for i in range(n):
  print(e[i].index(min(e[i]))+1)

Solution (Python):
n,m=raw_input().split(' ')
n=int(n)
m=int(m)

students=[]
for _ in range(n):
    x,y=raw_input().split(' ')
    students.append((int(x),int(y)))

checkpoint=[]
for _ in range(m):
    x,y=raw_input().split(' ')
    checkpoint.append((int(x),int(y)))

for s in students:
    min_d=99999999999
    min_num=0
    for i,c in enumerate(checkpoint):
        if abs(c[0]-s[0])+abs(c[1]-s[1]) < min_d:
            min_d=abs(c[0]-s[0])+abs(c[1]-s[1])
            min_num=i

    print min_num+1

Solution (Python):



import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n, m = map(int, input().split())
        students = []
        for i in range(n):
            a, b = map(int, input().split())
            students.append((a, b))
        checkpoints = []
        for j in range(m):
            c, d = map(int, input().split())
            checkpoints.append((c, d))
        for a, b in students:
            ans = -1
            minimum = float('inf')
            for index, (c, d) in enumerate(checkpoints):
                if minimum > abs(a - c) + abs(b - d):
                    minimum = abs(a - c) + abs(b - d)
                    ans = index + 1
            print(ans)
                
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Solution (Python):
n, m = map(int, input().split())

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

for i in range(n):
    a[i][0], a[i][1] = map(int, input().split())

for i in range(m):
    c[i][0], c[i][1] = map(int, input().split())

index = 0


for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)

Solution (Python):

n,m = map(int,input().split())
aa = [list(map(int,input().split())) for i in range(n)]
cc = [list(map(int,input().split())) for i in range(m)]

checkpoints = []
for a in aa:
    d = float("inf")
    checkpoint = -1
    for i,c in enumerate(cc):
        tmpd = min(abs(a[0]-c[0])+abs(a[1]-c[1]),d)
        if not tmpd == d:
            checkpoint = i+1
        d = tmpd
    print(checkpoint)

Solution (Python):
n, m = map(int, raw_input().split())
a, b = [], []
c, d = [], []

for i in range(n):
    a0, b0 = map(int, raw_input().split())
    a.append(a0)
    b.append(b0)
for i in range(m):
    c0, d0 = map(int, raw_input().split())
    c.append(c0)
    d.append(d0)
for i in range(n):
    res = 10**9
    ans = 0
    for j in range(m):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        if res > man:
            res = man
            ans = j
    print ans+1

Solution (Python):
nm = list(map(int, input().split()))

N = nm[0]
M = nm[1]

A = []
for i in range(0,N):
    A.append( list(map(int, input().split())) )

B = []
for i in range(0,M):
    B.append( list(map(int, input().split())) )

for a in A:
    min_d = 1000000000000000000000000
    min_i = 0
    d = 0
    for i, b in enumerate(B):
        d = abs(a[0]-b[0])+abs(a[1]-b[1])
        if d < min_d:
            min_i = i
            min_d = d
    print(min_i+1)

Solution (Python):
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())
def nil(): return list(map(int, stdin.readline().split()))

n, m = nil()

a = []
b = []
c = []
d = []

x = []
ans = []

for i in range(n):
    u, v = nil()
    a.append(u)
    b.append(v)
for i in range(m):
    u, v = nil()
    c.append(u)
    d.append(v)

for i in range(n):
    x.append(INF)
    ans.append(0)
    for j in range(m):
        t = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if(x[i] > t):
            ans[i] = j
            x[i] = t

for i in ans:
    print(i+1)

Solution (Python):



n,m=map(int,input().split())
g={int(i):[] for i in range(n)}
for i in range(n):
    x,y=map(int,input().split())
    g[i].append((x,y))

for i in range(m):
    x,y=map(int,input().split())
    for j in range(n):
        tmp=abs(g[j][0][0]-x)+abs(g[j][0][1]-y)
        if i==0:
            g[j].append(tmp)
            g[j].append(i)
        elif tmp<g[j][1]:
            g[j][1]=tmp
            g[j][2]=i
for i in range(n):
    print(g[i][2]+1)

Solution (Python):
N,M = [int(i) for i in input().split()]
a = [0]*N
b = [0]*N
c = [0]*M
d = [0]*M

for i in range(N):
    a[i], b[i] = [int(i) for i in input().split()]

for i in range(M):
    c[i], d[i] = [int(i) for i in input().split()]

for n in range(N):
    near_point = 0
    shortest = 10**9
    for m in range(M):
        manhattan = abs(a[n] - c[m]) + abs(b[n] - d[m])
        if manhattan < shortest:
            shortest = manhattan
            near_point = m + 1
    print(near_point)

Solution (Python):


import sys

def main(argv):
    line = sys.stdin.readline().rstrip("\n")

    while line:
        n, m = map(lambda x: int(x), line.split(" ", 2))

        students = []
        points = []
        for i in xrange(n):
            x, y = map(lambda x: int(x), raw_input().split(" ", 2))
            students.append((x, y))

        for i in xrange(m):
            x, y = map(lambda x: int(x), raw_input().split(" ", 2))
            points.append((x, y))

        for sx, sy in students:
            min_index = -1
            min_distance = 4 * 100000000

            for (i, (px, py)) in enumerate(points):
                distance = abs(sx - px) + abs(sy - py)
                if distance < min_distance:
                    min_distance = distance
                    min_index = i + 1
            print min_index

        line = sys.stdin.readline().rstrip("\n")

if __name__ == "__main__":
    main(sys.argv)

Solution (Python):
def MD(a1, a2):
    return abs(a1[0]-a2[0]) + abs(a1[1]-a2[1])
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
c = []
d = []
for i in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for A, B in zip(a, b):
    min_d = 10 ** 10
    for i, (C, D) in enumerate(zip(c, d)):
        md = MD((A, B), (C, D))
        if md < min_d:
            ans = i + 1
            min_d = md
    print(ans)

Solution (Python):

import sys

a, b, x, y = [], [], [], []
oo = 168430090

def rdl():
	return map(int, raw_input().split())


def mht(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)



n, m = rdl()
for i in range(n):
	l, r = rdl()
	x.append(l), y.append(r)

for i in range(m):
	l, r = rdl()
	a.append(l), b.append(r)

for i in range(n):
	mn, mnid = oo, 0
	for j in range(m):
		if mht(x[i], y[i], a[j], b[j]) < mn:
			mn = mht(x[i], y[i], a[j], b[j])
			mnid = j
	
	print mnid + 1

Solution (Python):
n, m = map(int, input().split())
a_b = [list(map(int, input().split())) for i in range(n)]
c_d = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    min_dis = 400000000
    min_dis_ind = 0
    for j in range(m):
        tmp = abs(a_b[i][0] - c_d[j][0]) + abs(a_b[i][1] - c_d[j][1])
        if min_dis > tmp:
            min_dis = tmp
            min_dis_ind = j
    print(min_dis_ind  + 1)

Solution (Python):
N, M = map(int, input().split())
n = [list(map(int, input().split())) for x in range(N)]
m = [list(map(int, input().split())) for x in range(M)]

for i in n:
    x = 0
    for j in range(M):
        c = m[j]
        k = m[x]
        a = max(i[0], k[0]) - min(i[0], k[0]) + max(i[1], k[1]) - min(i[1], k[1])
        b = max(i[0], c[0]) - min(i[0], c[0]) + max(i[1], c[1]) - min(i[1], c[1])
        if b < a : x = j
    print(x + 1)

Solution (Python):

N, M = [int(n) for n in input().split()]
students = []
check_points = []

for n in range(N):
    students.append([int(tmp) for tmp in input().split()])

for m in range(M):
    check_points.append([int(tmp) for tmp in input().split()])

for student in students:
    destination = 0
    min_dis = 10**16
    for i, check_point in enumerate(check_points):
        tmp_dis = abs(student[0] - check_point[0]) + abs(student[1] - check_point[1])
        if tmp_dis < min_dis:
            destination = i + 1
            min_dis = tmp_dis
    print(destination)

Solution (Python):
N, M = map(int, raw_input().split())

a = []
b = []
for i in range(N):
    temp1, temp2 = map(int, raw_input().split())
    a.append(temp1)
    b.append(temp2)

c = []
d = []
for i in range(M):
    temp1, temp2 = map(int, raw_input().split())
    c.append(temp1)
    d.append(temp2)

result = []

for student in range(N):
    maxDistance = 0
    closePoint = 0
    for point in range(M):
        distance = abs(c[point] - a[student]) + abs(d[point] - b[student])
        if point == 0 or distance < maxDistance:
            maxDistance = distance
            closePoint = point + 1
    result.append(closePoint)

for c in result:
    print(c)

Solution (Python):
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def dist(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func()
    top_str = input_raw.strip().split()
    [N, M] = [int(top_str[0]), int(top_str[1])]

    student_list = []
    checkpoint_list = []
    for i in range(N):
        input_raw = read_func().split()
        (a, b) = (int(input_raw[0]) , int(input_raw[1]))
        student_list.append((a,b))

    for i in range(M):
        input_raw = read_func().split()
        (c, d) = (int(input_raw[0]) , int(input_raw[1]))
        checkpoint_list .append((c, d))

    for i in range(N):
        min_checkpoint = 0
        min_dist = sys.maxint
        studentpoint = student_list[i]
        for j in range(M):
            checkpoint = checkpoint_list[j]
            d = dist(studentpoint[0], studentpoint[1], checkpoint[0], checkpoint[1])
            if d < min_dist:
                min_checkpoint = j
                min_dist = d
        print min_checkpoint + 1


if __name__ == '__main__':
    main()

Solution (Python):
def distance(sX, sY, pX, pY):
	return abs(sX-pX) + abs(sY-pY)

def getIndex(stuX, stuY, points):
	minDist = -1
	index = 0
	for i in range(len(points)):
		pX = points[i][0]
		pY = points[i][1]
		if (minDist == -1 or distance(stuX, stuY, pX, pY) < minDist):
			minDist = distance(stuX, stuY, pX, pY)
			index = i + 1
	return index

[N, M] = input().split()
N = int(N)
M = int(M)
stus = []
points = []
for n in range(N):
	[x,y] = input().split()
	x = int(x)
	y = int(y)
	stus.append([x, y])
for m in range(M):
	[x,y] = input().split()
	x = int(x)
	y = int(y)
	points.append([x,y])
for s in stus:
	print(getIndex(s[0], s[1], points))

Solution (Python):
if __name__ == '__main__':
    n, m = map(int, input().split())
    students, checkpoints = (tuple(tuple(map(int, input().split())) for _ in range(x)) for x in (n, m))

    for x1, y1 in students:
        t = 0
        for i in range(m):
            (x2, y2), (x3, y3) = checkpoints[t], checkpoints[i]
            if abs(x1 - x2) + abs(y1 - y2) > abs(x1 - x3) + abs(y1 - y3): t = i

        print(t + 1)

Solution (Python):
import math

n,m=[int(i) for i in input().split()]
ab=[]
cd=[]
for i in range(n):
    x,y=[int(i) for i in input().split()]
    ab.append([x,y])
for i in range(m):
    x,y=[int(i) for i in input().split()]
    cd.append([x,y])


for i in range(n):
    dist=1000000000
    point=0
    for j in range(m):
        temp=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if temp<dist:
            dist=temp
            point=j+1
    print(point)

Solution (Python):
N, M = map(int, input().split())
As = []
Bs = []
for _ in range(N):
    a, b = map(int, input().split())
    As.append(a)
    Bs.append(b)
Cs = []
Ds = []
for _ in range(M):
    c, d = map(int, input().split())
    Cs.append(c)
    Ds.append(d)

ans = []
for i in range(N):
    a = As[i]
    b = Bs[i]
    dist = 5 * 10**8
    tmp = 1
    for j in range(M):
        c = Cs[j]
        d = Ds[j]
        if abs(a - c) + abs(b - d) < dist:
            dist = abs(a - c) + abs(b - d)
            tmp = j + 1
    ans.append(tmp)
    
print('\n'.join(list(map(str, ans))))

Solution (Python):

def amin(_data):
    ans = 0
    dst = 1000000000

    for idx, point in enumerate(checks):
        
        
        x = abs(_data[0] - point[0])
        y = abs(_data[1] - point[1])

        _dst = x + y

        if _dst < dst:
            ans = idx + 1
            dst = _dst

    return ans



N, M = list(map(int, input().split()))
points = list()
checks = list()

for _ in range(N):
    data = list(map(int, input().split()))
    points.append(data)

for _ in range(M):
    data = list(map(int, input().split()))
    checks.append(data)

for point in points:
    print(amin(point))

Solution (Python):
N, M  = list(map(int,input().split()))

gaku = []
for i in range(N):
	gaku.append(tuple(map(int,input().split())))

cp = []
for i in range(M):
	cp.append(tuple(map(int,input().split())))

def dis(x,y,a,b):
	return(abs(x-a)+abs(y-b))

res = []

for x,y in (gaku):
	c = 1
	mind = float("inf")
	minc = 0
	for a,b in (cp):
		if dis(x,y,a,b) < mind:
			minc = c
			mind = dis(x,y,a,b)
		c+=1
	res.append(minc)


for i in res:
	print(i)

Solution (Python):
N, M = map(int, input().split())

a = []
b = []
c = []
d = []

for _ in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)

for _ in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for i in range(N):
    maxIdx = 0
    for j in range(M):
        d1 = abs(a[i] - c[j]) + abs(b[i] - d[j])
        d2 = abs(a[i] - c[maxIdx]) + abs(b[i] - d[maxIdx])
        if d1 < d2:
            maxIdx = j

    print(maxIdx + 1)

Solution (Python):
n,m = map(int, input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
c = [0 for i in range(m)]
d = [0 for i in range(m)]
for i in range(n):
	a[i],b[i] = map(int, input().split())
for i in range(m):
	c[i],d[i] = map(int, input().split())

def dist(a,b,c,d):
	return abs(a-c)+abs(b-d)

for i in range(n):
	aa,bb = a[i],b[i]
	ans = []
	for j in range(m):
		ans.append((dist(aa,bb,c[j],d[j]),j))
	ans.sort()
	print(ans[0][1]+1)

Solution (Python):
class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
def diff(p1, p2):
    return abs(p1.x - p2.x) + abs(p1.y - p2.y)
N, M = map(int, raw_input().split())
S = []
for i in xrange(N):
    x, y = map(int, raw_input().split())
    s = Point(x, y)
    S.append(s)
C = []
for i in xrange(M):
    x, y = map(int, raw_input().split())
    c = Point(x, y)
    C.append(c)
for s in S:
    index = None
    dist = 1e9
    for i, c in enumerate(C):
        d = diff(s, c) 
        if d < dist:
            dist = d
            index = i
    print index + 1

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    b = [LI() for _ in range(m)]
    r = []
    for ai in a:
        mi = -1
        mm = inf
        for i in range(m):
            bi = b[i]
            t = abs(ai[0]-bi[0]) + abs(ai[1]-bi[1])
            if t < mm:
                mi = i+1
                mm = t
        r.append(mi)

    return '\n'.join(map(str, r))



print(main())

Solution (Python):
INF = 10 ** 10

n,m = map(int,input().split(' '))
a = [0] * n
b = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split(' '))
c = [0] * m
d = [0] * m
for i in range(m):
    c[i],d[i] = map(int,input().split(' '))

for i in range(n):
    mn = INF
    mi = -1
    for j in range(m):
        x = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if x < mn:
            mn = x
            mi = j
    print(mi+1)

Solution (Python):
if __name__ == '__main__':
    N,M = map(int, input().split())
    data = []
    for i in range(N):
        a,b = map(int, input().split())
        data.append([a, b])
    checks = []
    for i in range(M):
        c,d = map(int, input().split())
        checks.append([c, d])

    for a,b in data:
        res = 1 << 50
        p = -1
        for idx, check in enumerate(checks):
            tmp = abs(a - check[0]) + abs(b - check[1])
            if (tmp < res):
                res = tmp
                p = idx + 1
        print (p)

Solution (Python):
def ri():
    return map(int, raw_input().split())

n,m = ri()
students = [ri() for _ in range(n)]
checkpoints = [ri() for _ in range(m)]
for a,b in students:
    idx = -1
    dist = 10**9
    for i,(c,d) in enumerate(checkpoints):
        tmp = abs(c-a) + abs(d-b)
        if tmp < dist:
            dist = tmp
            idx = i
    print idx + 1

Solution (Python):
N, M = map(int, input().split())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

C, D = [], []
for i in range(M):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

for a, b in zip(A, B):
    best = 1<<30
    res = None
    for i in range(M):
        d = abs(a - C[i]) + abs(b - D[i])
        if res is None or best > d:
            best = d
            res = i
    print(res + 1)

Solution (Python):
n, m = map(int, raw_input().split())

stu = []
che = []
ans = []

for i in xrange(n):
    a, b = map(int, raw_input().split())
    stu.append((a, b))
    
for i in xrange(m):
    a, b = map(int, raw_input().split())
    che.append((a, b))
    
for i in xrange(n):
    dis = float('inf')
    for j in xrange(m):
        if abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1]) < dis:
            index = j
            dis = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1])
    ans.append(index)
    
for i in ans:
    print i+1

Solution (Python):
def md(a,b,c,d):
    return abs(a-c) + abs(b-d)
n,m = map(int, input().split())
s = []
for i in range(n):
    y,x = map(int, input().split())
    s.append((y,x))
c = []
for i in range(m):
    y,x = map(int, input().split())
    c.append((y,x))
for i in range(n):
    min_j = 0
    min_d = float('inf')
    for j in range(m):
        d = md(s[i][0], s[i][1], c[j][0], c[j][1])
        if min_d > d:
            min_j = j
            min_d = d
    print(min_j+1)

Solution (Python):
n,m=map(int,raw_input().split())
ab=[map(int,raw_input().split()) for _ in xrange(n)]
cd=[map(int,raw_input().split()) for _ in xrange(m)]
ans=[]
for i in xrange(n):
    a,b=ab[i]
    tmp=10**12
    idx=-1
    for j in xrange(m):
        c,d=cd[j]
        if abs(a-c)+abs(b-d)<tmp:
            tmp=abs(a-c)+abs(b-d)
            idx=j
    ans.append(idx)
for i in xrange(n):
    print ans[i]+1

Solution (Python):
import sys

def solve():
    N, M = map(int, input().split())
    st = [[int(i) for i in input().split()] for j in range(N)]
    cp = [[int(i) for i in input().split()] for j in range(M)]

    for a, b in st:
        ans = 0
        min_len = 10**9

        for i, (c, d) in enumerate(cp):
            tmp = abs(c - a) + abs(d - b)
            if tmp < min_len:
                min_len = tmp
                ans = i + 1

        print(ans)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Solution (Python):
import sys

stdin = sys.stdin


def na(): return map(int, stdin.readline().split())


def ns(): return stdin.readline().strip()


n,m=na()
abss = []
for i in range(n):
    abss.append(list(na()))
cds = []
for i in range(m):
    cds.append(list(na()))

for ab in abss:
    mind = 999999999
    argmin = -1
    import math
    for j in range(m):
        v = abs(cds[j][0]-ab[0])+abs(cds[j][1]-ab[1])
        if v < mind:
            mind = v
            argmin = j
    print(argmin+1)

Solution (Python):
N, M = map(int, raw_input().split())
ab = [map(int, raw_input().split()) for _ in xrange(N)]
cd = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    mi = -1
    mv = float('inf')
    for j in xrange(M):
        dist = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if dist < mv:
            mv = dist
            mi = j
    print mi+1