#include <stdio.h>
#include <stdlib.h>
int c(const void *v1,const void *v2){
    return *(int *)v1-*(int *)v2;
}
int main(void){
    int num,linex[199],liney[199],i,n,d,x,y;
    linex[0]=0,liney[0]=0;
    for(;scanf("%d",&num),num;){
        for(i=0;x=0,y=0,i<num-1;i++){
            scanf("%d %d",&n,&d);
            switch(d){
                case 0:x=-1; break;
                case 1:y=1;  break;
                case 2:x=1;  break;
                case 3:y=-1; break;
            }
            linex[i+1]=linex[n]+x;
            liney[i+1]=liney[n]+y;
        }
        qsort(linex,num,4,c);
        qsort(liney,num,4,c);
        for(x=0,y=0,i=1;i<num;i++){
            if(linex[i]==linex[i-1])
                x++;
            if(liney[i]==liney[i-1])
                y++;
        }
        printf("%d %d\n",num-x,num-y);
    }
    return 0;
}