/*
 * Faculty of Applied Science and Engineering, University of Toronto
 * CSC181: Introduction to Computer Programming, Fall 2000
 *
 * Assignment 1 Solution (Task 1)
 * Author: Ray Ortigas (rayo@dgp.toronto.edu)
 */

#include <stdio.h>
#include <math.h>

/* Represents a point on a 2-D plane. */
typedef struct {
	/* The x-coordinate of this point. */
	int x;

	/* The y-coordinate of this point. */
	int y;
} Point;

/* Returns the (Euclidean) distance between a and b. */
double distanceBetweenPoints(const Point a, const Point b) {
	double dx = a.x - b.x;
	double dy = a.y - b.y;
	return sqrt(dx*dx + dy*dy);
}

/* Creates and returns the point whose coordinates are taken from
   the standard input. */
Point readPoint() {
	Point result;
	scanf("%d %d", &(result.x), &(result.y));
	return result;
}

/* Main program. */
int main(void) {

	/* The initial point. */
	Point p0;

	/* The number of other points. */
	int n;

	/* Read in the initial point. */
	p0 = readPoint();

	/* Read in the other points, but not before reading in
	   how many points there are. */
	scanf("%d", &n);
	if (n >= 2) {
		/* The nearest and second-nearest points to p0. */
		Point nearest, secondNearest;

		/* The first two points from the rest of the points. */
		Point p1, p2;

		/* A counter variable for when we read in the rest of 
		   the points. */
		int i;

		/* Read in the first two points and figure out which of the two 
		   should be the nearest and second-nearest, initially. */
		p1 = readPoint();
		p2 = readPoint();
		if (distanceBetweenPoints(p1, p0) < distanceBetweenPoints(p2, p0)) {
			nearest = p1;
			secondNearest = p2;
		}
		else {
			nearest = p2;
			secondNearest = p1;
		}

		/* Read in the remaining points, updating nearest and
		   secondNearest, as necessary. */
		for (i = 2; i < n; i++) {
			Point pn = readPoint();
			if (distanceBetweenPoints(pn, p0)
				< distanceBetweenPoints(nearest, p0)) {
				secondNearest = nearest;
				nearest = pn;
			}
			else if (distanceBetweenPoints(pn, p0) 
				< distanceBetweenPoints(secondNearest, p0)) {
				secondNearest = pn;
			}
		}

		/* Print out the nearest and second-nearest points to p0. */
		printf("%d %d\n", nearest.x, nearest.y);
		printf("%d %d\n", secondNearest.x, secondNearest.y);
	}

	return 0;
}
