Under construction

Still being built. Things may change

Two covers

Interview

Time limit3sMemory limit1024 MB

Summary
Count positions x that lack both a piece reaching k letters left of x and a different piece reaching k letters right of x.
Level

Medium4 of 10

Topics
Array, Prefix sum, Sorting
Solved
No attempts yet

Statement

In a typical genome assembly problem, we are given a set of small strings called pieces, and our task is to find a superstring of them with some reasonable properties. In this problem, you are given one such superstring and a collection of pieces aligned to it. Your task is to evaluate one particular property.

You are given the length of the superstring ℓ, a list of nn pieces, and a number kk. The positions in the superstring are numbered from 1 to ℓℓ. For each piece ii, you are given the positions (bi,ei)(b_i, e_i) of its beginning and end.

The letter at position xx in the superstring is well-covered if:

  • There is a piece (bi,ei)(b_i, e_i) such that bi≤x−kb_i ≤ x − k and x≤eix ≤ e_i.
  • There is a different piece (bj,ej)(b_j, e_j) such that bj≤xb_j ≤ x and x+k≤ejx + k ≤ e_j.

Your task is to count the number of letters which are not well-covered.

Input

The first line contains an integer tt, the number of test cases. Each test case is preceded by a blank line.

Each test case starts with a line containing three integers ℓℓ, nn, and kk. Each of the following nn lines contains two integers bib_i and eie_i (1≤bi≤ei≤ℓ1 ≤ b_i ≤ e_i ≤ ℓ), the endpoints of a piece. The pairs (bi,ei)(b_i, e_i) are all distinct.

Output

For each test case, output a single line with a single integer: the number of letters that are not well-covered.

Hint

The well-covered letters are at positions 3, 4, and 5. The letter at position 6 is not well-covered.

Examples1

  1. Example 1

    Input
    1
    
    8 3 2
    1 4
    3 5
    4 8
    
    Expected output
    5