import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Function         (on)
import qualified Data.Sequence         as S
import Data.List (sort)

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

first :: (a, a, a) -> a
first (x, _, _) = x

second :: (a, a, a) -> a
second (_, x, _) = x

third :: (a, a, a) -> a
third (_, _, x) = x

data Tree a
    = Leaf
    | Node a (Tree a) (Tree a)
    deriving Show

makeTree :: S.Seq (Int, Int, Int) -> Tree (Int, Int, Int)
makeTree s = go 1 s
  where
    split m s = (\(l,r) -> (l, S.drop 1 r)) $ S.splitAt m s
    go depth s
        | S.null s  = Leaf
        | odd depth =
              let (l, r) = split mid sx
               in Node (sx `S.index` mid) (go (depth + 1) l) (go (depth + 1) r)
        | otherwise =
              let (l, r) = split mid sy
               in Node (sy `S.index` mid) (go (depth + 1) l) (go (depth + 1) r)
      where
        mid = S.length s `div` 2
        sx = S.unstableSortBy (compare `on` second) s
        sy = S.unstableSortBy (compare `on` third) s

range :: [Int] -> Tree (Int, Int, Int) -> [Int]
range [sx,tx,sy,ty] t = go 1 t []
  where
    go _     Leaf               as = as
    go d (Node (i,x,y) l r) as
        | odd d = case () of
              _ | sx <= x && x <= tx
                , sy <= y && y <= ty -> i : go (d + 1) l (go (d + 1) r as)
                | sx <= x && x <= tx -> go (d + 1) l (go (d + 1) r as)
                | x < sx -> go (d + 1) r as
                | x > tx -> go (d + 1) l as
        | otherwise = case () of
              _ | sx <= x && x <= tx
                , sy <= y && y <= ty -> i : go (d + 1) l (go (d + 1) r as)
                | sy <= y && y <= ty -> go (d + 1) l (go (d + 1) r as)
                | y < sy -> go (d + 1) r as
                | y > ty -> go (d + 1) l as

main :: IO ()
main = do
    let f (x,(y,z)) = (x,y,z)
    n <- readLn
    ns <- fmap (S.fromList . fmap f . zip [0..]) . replicateM n $ do
        [x,y] <- fmap readi . B.words <$> B.getLine
        return (x, y)
    q <- readLn
    qs <- fmap (fmap readi . B.words) <$> replicateM q B.getLine

    let tree = makeTree ns
    let xss = fmap (flip range tree) qs

    forM_ xss $ \xs -> do
        mapM_ print (sort xs)
        putStrLn ""

