#include <stdio.h>

#define LEFT   0
#define BOTTOM 1
#define RIGHT  2
#define TOP    3

typedef struct {
  int n, d;
  int x, y;
} s_square;

int main() {
  int n, x_min, y_min, x_max, y_max;
  s_square square[200];
  square[0] = {0};  //´_ðú»

  int i;
  while(1) {
    scanf("%d", &n);
    if(n == 0) { break; }

    for(i = 1; i < n; i ++) {
      scanf("%d %d", &square[i].n, &square[i].d);
    }

    x_min = y_min = x_max = y_max = 0;

    for(i = 1; i < n; i ++) {
      switch(square[i].d)
	case(LEFT) {
	  square[i].x = square[square.n].x - 1;
	  square[i].y = square[square.n].y
	  break;
	}
	case(BOTTOM) {
	  square[i].x = square[square.n].x
	  square[i].y = square[square.n].y - 1;
	  break;
	}
	case(RIGHT) {
	  square[i].x = square[square.n].x + 1;
	  square[i].y = square[square.n].y
	  break;
	}
	case(TOP) {
	  square[i].x = square[square.n].x
	  square[i].y = square[square.n].y + 1;
	  break;
	}

	//ÀW[ÌXV
	     if(square[i].x < x_min) { x_min = square[i].x; }
	else if(x_max < square[i].x) { x_max = square[i].x; }

	     if(square[i].y < y_min) { y_min = square[i].y; }
	else if(y_max < square[i].y) { y_max = square[i].y; }
    }

    printf("%d %d/n", x_max - x_min, y_max - y_min);
  }

  return 0;
}