// AOJ ALDS1_3_B Queue
// 2018.4.30 bal4u

#include <stdio.h>

#define MAX_N 100002

typedef struct { char *p; int tm; } Q;
Q que[(MAX_N<<1)+2]; int top, end;
char name[MAX_N][20];

char buf[20], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int  n, q, tm, i;
	Q  t;

