#include <stdio.h>
int main()
{
int x, y, time, temp, command, div;
x = y = temp = div = 0;
while (scanf("%d%d", &time, &command) == 2)
{
switch (div)
{
case 0 : y += (time-temp)*10; break;
case 1 : x -= (time-temp)*10; break;
case 2 : y -= (time-temp)*10; break;
case 3 : x += (time-temp)*10; break;
}
if (3 == command)
break;
if (2 == command)
div--;
if (1 == command)
div++;
div = (div+4) % 4;
temp = time;
}
printf("%d %d", x, y);
return 0;
}