import std.stdio, std.string, std.array, std.algorithm, std.conv;

struct Record {
  int t;
  int n;
  int m;
  int s;

  int opCmp( Record r ) {
	if ( t != r.t ) {
	  return t - r.t;
	} else {
	  if ( s == 0 && r.s == 0 ) {
		return r.n - n;
	  } else if ( s == 1 && r.s == 1 ) {
		return n - r.n;
	  }	else {
		return 0;
	  }
	}
  }

  bool opEquals( Record r ) {
	return t == r.t && n == r.n && m == r.m && s == r.s;
  }
}

void main()
{
  int count = 0;
  while ( true ) {
	// stderr.writeln( ++count, " th try start." );
	auto token = array( map!( to!int )( split( strip( readln ) ) ) );
	int N = token[ 0 ];
	int M = token[ 1 ];
	if ( N == 0 && M == 0 ) break;
	int r = to!int( strip( readln ) );
	Record[] rs = new Record[]( r );
	foreach ( i; 0 .. r ) {
	  auto record = array( map!( to!int )( split( strip( readln ) ) ) );
	  rs[ i ] = Record( record[ 0 ], record[ 1 ], record[ 2 ], record[ 3 ] );
	}
	int q = to!int( strip( readln ) );
	foreach ( i; 0 .. q ) {
	  auto question = array( map!( to!int )( split( strip( readln ) ) ) );
	  writeln( solve( rs, question ) );
	}
  }  
}

int solve( Record[] rs, int[] question ) {
  Record[] rrs = new Record[]( rs.length + 2 );
  rrs[ 2 .. $ ] = rs[];
  auto start = Record( question[ 0 ], -1, -1, 1 );
  auto end = Record( question[ 1 ], -1, -1, 0 );
  rrs[ 0 ] = start;
  rrs[ 1 ] = end;
  sort( rrs );
  int ans = 0;
  int count = 0;
  bool ok = false;
  Record prev = Record( 540, -1, -1, -1 );
  // stderr.writeln( rrs );
  foreach ( i, r; rrs[ 0..$-1 ] ) {
	// stderr.writeln( r );
	if ( r == start ) {
	  // stderr.writeln( "start" );
	  ok = true;
	} else if ( r == end ) {
	  // stderr.writeln( "end" );
	  ok = false;
	  break;
	} 
	if ( r.m == question[ 2 ] && r.s == 1 ) {
	  // stderr.writeln( "count++, ", count + 1 );
	  count++;
	} else if ( r.m == question[ 2 ] && r.s == 0 ) {
	  // stderr.writeln( "count--, ", count - 1 );
	  count--;
	}
	if ( ok && count > 0 ) {
	  // stderr.writeln( "add time, ", rrs[ i + 1 ].t - rrs[ i ].t );
	  ans += rrs[ i + 1 ].t - rrs[ i ].t;
	}
  }
  return ans;
}