// Problem H. Biggest Space
// By Jittat Fakcharoenphol	
// ACM-ICPC Thailand 2009

#include <cstdio>

#define MAX_N   50

struct Shape {
  int t;
  int x1, y1, x2, y2;
  int r;
};

int n, l, w;
Shape shapes[MAX_N];

void read_input()
{
  scanf("%d %d %d",&l,&w,&n);
  for(int i=0; i<n; i++) {
    int t;
    scanf("%d",&shapes[i].t);
    if(shapes[i].t==0) {
      // circle
      scanf("%d %d %d",&shapes[i].x1,
	    &shapes[i].y1, &shapes[i].r);
    } else {
      // rectangle
      scanf("%d %d %d %d",&shapes[i].x1, &shapes[i].y1, 
	    &shapes[i].x2, &shapes[i].y2);
    }
  }
}

// checks if (a1,a2) intersects with (b1,b2)
// only works when a1 < a2, and b1 < b2.
bool range_intersection(int a1, int a2,
			int b1, int b2)
{
  return (a1 < b2) && (b1 < a2);
}

bool check_rectangle_intersection(int x11, int y11, int x12, int y12,
				  int x21, int y21, int x22, int y22)
{
  return range_intersection(x11, x12, x21, x22) &&
    range_intersection(y11, y12, y21, y22);
}

bool in_circle(int cx, int cy, int cr,
	       int x, int y)
{
  return (x-cx)*(x-cx) + (y-cy)*(y-cy) < cr*cr;
}

bool in_or_on_rectangle(int x1, int y1, int x2, int y2,
			int x, int y)
{
  return (x1<=x) && (x<=x2) &&
    (y1<=y) && (y<=y2);
}

bool check_circular_intersection(int cx, int cy, int cr,
				 int x1, int y1, int x2, int y2)
{
  if(in_or_on_rectangle(x1,y1,x2,y2, cx,cy))
    return true;

  if(in_circle(cx,cy,cr,x1,y1) ||
     in_circle(cx,cy,cr,x1,y2) ||
     in_circle(cx,cy,cr,x2,y1) ||
     in_circle(cx,cy,cr,x2,y2))
    return true;

  if((y1<cy) && (cy<y2)) {
    if(cx<x1)
      // from left
      return cx+cr>x1;
    else
      // from right
      return cx-cr<x2;
  } 
  if((x1<cx) && (cx<x2)) {
    if(cy<y1)
      // from top
      return cy+cr>y1;
    else
      // from bottom
      return cy-cr<y2;
  }
  return false;
}

int find_max()
{
  int max = 0;
  for(int x1=0; x1<l; x1++)
    for(int x2=x1+1; x2<=l; x2++)
      for(int y1=0; y1<w; y1++)
	for(int y2=y1+1; y2<=w; y2++) {
	  int a = (x2-x1)*(y2-y1);
	  if(a<=max)
	    continue;
	  bool dead = false;
	  for(int i=0; (i<n) && (!dead); i++) {
	    if((shapes[i].t==0) &&
	       check_circular_intersection(shapes[i].x1, 
					   shapes[i].y1,
					   shapes[i].r,
					   x1,y1,x2,y2))
	      dead = true;
	    if((shapes[i].t==1) &&
	       check_rectangle_intersection(shapes[i].x1,
					    shapes[i].y1,
					    shapes[i].x2,
					    shapes[i].y2,
					    x1,y1,x2,y2))
	      dead = true;
	  }
	  if(!dead) {
	    //printf("%d %d %d %d %d\n",a,x1,y1,x2,y2);
	    max = a;
	  }
	}
  return max;
}

main()
{
  int c;
  scanf("%d",&c);
  for(int i=0; i<c; i++) {
    read_input();
    printf("%d\n",find_max());
  }
}

