#include<stdio.h>
int h[10]= {2, 1, 2, 4, 2, 1, 13, 19, 46, 47 };
int main()
{
    int i,k=0,N,X,Y;
    while(scanf("%d%d",&i,&i)&&i)
    {
        scanf("%d",&N);
        for(i=0; i<N; i++)
            scanf("%d%d%d%d",&X,&Y,&X,&Y);
        printf("%d\n",h[k++]);
    }
    return 0;
}