#include <stdio.h>
#include <string.h>

#define N 10000

int d[ N ][ 721 ];

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int pcn, stdn;
    int r, q;

    scanf ( "%d%d", &pcn, &stdn );
    if ( !( pcn | stdn ) ) break ;

    memset ( d, 0, sizeof ( d ) );
    scanf ( "%d", &r );
    while ( r-- )
    {
      int t, pc, std, s;

      scanf ( "%d%d%d%d", &t, &pc, &std, &s );
      d[ std - 1 ][ t - 540 ] = ( s ? 1 : -1 );
    }
    for ( i = 0; i < stdn; ++i )
    {
      int su = 0;
      int st = 0;

      for ( j = 0; j <= 720; ++j )
      {
        su += !!( st );
        st += d[ i ][ j ];
        d[ i ][ j ] = su;
      }
    }

    scanf ( "%d", &q );
    while ( q-- )
    {
      int ts, te, std;

      scanf ( "%d%d%d", &ts, &te, &std );
      printf ( "%d\n", d[ std - 1 ][ te - 540 ] - d[ std - 1 ][ ts - 540 ] );
    }
  }

  return ( 0 );
}