#!/usr/bin/env python3


import time

def main():
    start = time.time()
    guards = list()
    incidents = list()
    outputs = list()

    line0 = [int(i) for i in input().split()]
    n_guards = line0[0]
    n_inc = line0[1]

    for i in range(n_guards):
        guards.append(
            [int(i) for i in input().split()]
        )


    for i in range(n_inc):
        incidents.append(
            [int(i) for i in input().split()]
        )


    for inc in incidents:
        shortest_dist = None
        for g in guards:
            dist = ( (inc[0] - g[0]) ** 2 + (inc[1] - g[1]) ** 2 ) ** 0.5
            if shortest_dist is None or dist < shortest_dist:
                shortest_dist = dist
        outputs.append(str(round(shortest_dist)))

    print("\n".join(outputs))


    print("End time: " + str(time.time() - start))


if __name__ == '__main__':
    main()
