#include <stdio.h>

#define N 100000

typedef struct{
	char c;
	int num;
} Card;

void swap(int *a, int *b) {
	int tmp;

	tmp = *a;
	*a = *b;
	*b = tmp;
}

int partition(int* A, int p, int r) {
	int x, i, j;

	x = A[r];
	i = p - 1;

	for (j = p; j < r; ++j) {
		if (A[j] <= x) {
			i++;
			swap(&A[i], &A[j]);
		}
	}
	swap(&A[i + 1], &A[r]);

	return i + 1;
}

void quickSort(Card *A, int p, int r) {
	int q;

	if (p < r) {
		q = partition(&A->num, p, r);
		quickSort(A, p, q - 1);
		quickSort(A, q + 1, r);
	}
}

int main() {
	int i, n;
	Card card[N];

	scanf("%d", &n);

	for (i = 0; i < n; ++i) {
		scanf("%c", &card[i].c);
		scanf("%d", &card[i].num);
	}

	quickSort(card, 0, n - 1);

	for (i = 0; i < n; ++i) {
		printf("%c %d\n", card[i].c, card[i].num);
	}

	return 0;
}