open Scanf
open Printf

let rec scan_list = function
  | 1 -> scanf "%d %d\n" (fun k j -> [k,j])
  | n -> scanf "%d %d\n" (fun k j -> (k,j) :: scan_list (n-1))

let h lrs p q = List.length @@ List.filter (function k,j -> p <= k && j <= q) lrs

let rec g q lrs = if q = 1
  then printf "%d\n" (scanf "%d %d" (h lrs))
  else printf "%d\n" (scanf "%d %d\n" (h lrs)); g (q-1) lrs

let f n m q = let lrs = scan_list m in g q lrs

let () = scanf "%d %d %d\n" f