T = int( input() )
def any(X):
# returns any element in X
for x in X: return x
return None
for test in range(T):
input() # discard the empty line
L, N, K = [ int(x) for x in input().split() ]
# E is a list of events
# each event has the form (index, begin, color, number), where:
# - index is the position where it happens
# - begin==0 if the event is an end of an interval, begin==1 if it is a begin
# - color==0 if it is an interval shortened at the end, color==1 if shortened at the beginning
# - number is the serial # of the original interval
E = []
for n in range(N):
b, e = [ int(x) for x in input().split() ]
if e-b < K: continue
E.append( ( b , 1, 0, n ) )
E.append( ( e-K+1, 0, 0, n ) )
E.append( ( b+K , 1, 1, n ) )
E.append( ( e+1 , 0, 1, n ) )
E.sort()
E.append( ( L+1, 1, 0, -47 ) ) # sentinel event
answer = 0
last_index = 1
open_intervals = [ set(), set() ]
for (index,begin,color,number) in E:
if index > last_index:
# we moved since the last event, are the indices we just passed well covered?
well_covered = True
if len(open_intervals[0]) == 0: well_covered = False
if len(open_intervals[1]) == 0: well_covered = False
if len(open_intervals[0]) == 1 and len(open_intervals[1]) == 1 and any(open_intervals[0]) == any(open_intervals[1]): well_covered = False
if not well_covered: answer += index - last_index
last_index = index
# process the current event
if begin == 1: open_intervals[color].add(number)
else: open_intervals[color].remove(number)
print(answer)