Edward Elric is chasing after Scar. To stop Edward, Scar creates $N$ barriers in the way, numbered from $1$ to $N$. 
Each barrier Scar created is either one of the following two types.
Type 1 barrier - This barrier starts from a height $X$ above the ground and extends till the sky.
Type 2 barrier - This barrier starts from the ground and extends up to height $X$ above the ground.

The height of Edward is $H$ units and he has an alchemic life force of $L$ units. Moreover, he can duck by $Y_{1}$ units and jump by height $Y_{2}$ units (as explained in the figures). He starts crossing barriers in sequence, starting from barrier $1$ till the barrier $N$. Whenever he can't pass a barrier by ducking or jumping (considered passed even when the barrier just touches him), he uses Alchemy to break the barrier. However, this costs him a single unit of his alchemic life force.

If after breaking a barrier no life force is left, Edward gets completely exhausted, unable to pass that barrier.   
How many barriers can Edward cross?   

And remember never to call him a pipsqueak if his height is too short!

------  Input: ------

The first line contains $T$, the number of test cases. Then the test cases follow. 
For each test case, the first line contains five integers $N$, $H$, $Y_{1}$, $Y_{2}$ and $L$.
The i-th of the next $N$ lines contains two integers $t_{i}$ and $X_{i}$ for the $i^{th}$ barrier where $t_{i} = 1$ denotes a Type 1 Barrier and $t_{i} = 2$ denotes a Type 2 barrier.
  
------  Output: ------
For each test case print a single line containing the number of barriers Edward can pass.
  
------  Constraints  ------
$1 ≤ T≤ 100$   
$1 ≤ N≤ 10^{3}$    
$2 ≤ H≤ 10^{3}$   
$1 ≤ Y_{1} < H$   
$1 ≤ Y_{2} ≤ 10^{3}$    
$1 ≤ L ≤ N$    
$1 ≤ t_{i} ≤ 2$
$1 ≤ X_{i}≤ 10^{3}$ 

----- Sample Input 1 ------ 
3
6 5 1 2 3
2 2
2 1
1 10
2 8
2 4
1 2
1 4 2 5 1
2 6
6 5 1 2 3
2 2
2 1
1 10
2 8
2 4
1 6
----- Sample Output 1 ------ 
5
0
6
----- explanation 1 ------ 
Test Case 1:    

Given $N = 6$, $H = 5$, $Y_{1} = 1$, $Y_{2} = 2$ and $L = 3$.    
He passes the first three barriers by either ducking or jumping. He uses alchemic life force for breaking $4^{th}$, $5^{th}$ and $6^{th}$ barriers because he cannot pass them by either jumping or ducking. He gets exhausted after breaking the $6^{th}$ barrier and is unable to pass it. So, in total he passes $5$ barriers.

Source: codechef | Difficulty: MEDIUM
Tags: Implementation


Solutions:
for _ in range(int(input())):
	(n, h, d, j, l) = map(int, input().split())
	(flag, count) = (1, 0)
	l -= 1
	for _ in range(n):
		(t, s) = map(int, input().split())
		if t == 1 and flag:
			if h - d <= s:
				count += 1
			elif l:
				count += 1
				l -= 1
			else:
				flag = 0
				continue
		elif t == 2 and flag:
			if s - j <= 0:
				count += 1
			elif l:
				count += 1
				l -= 1
			else:
				flag = 0
	print(count)


for tc in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	sco = 0
	ans = []
	for i in range(n):
		ele = map(int, input().split())
		ans.append(ele)
	for (t, x) in ans:
		dh = h - y1
		if t == 1:
			if x >= dh:
				sco += 1
			else:
				l -= 1
				if l:
					sco += 1
				else:
					break
		elif y2 >= x:
			sco += 1
		else:
			l -= 1
			if l:
				sco += 1
			else:
				break
	print(sco)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	b = []
	for i in range(n):
		b.append([int(j) for j in input().split()])
	ans = 0
	for i in b:
		if i[0] == 1 and h - y1 > i[1]:
			l -= 1
		if i[0] == 2 and y2 < i[1]:
			l -= 1
		if l > 0:
			ans += 1
		else:
			break
	print(ans)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split(' '))
	bar = []
	count = 0
	for _ in range(n):
		(tz, xz) = map(int, input().split(' '))
		bar.append((tz, xz))
	for i in range(n):
		if l > 0:
			(t, x) = bar[i]
			if t == 1:
				if h <= x:
					count += 1
					pass
				elif h - y1 <= x:
					count += 1
					pass
				else:
					l -= 1
					if l != 0:
						count += 1
			elif t == 2:
				if y2 < x:
					l -= 1
					if l != 0:
						count += 1
				else:
					count += 1
					pass
	print(count)


t = int(input())
for _ in range(t):
	(n, h, y1, y2, l) = map(int, input().split())
	count = 0
	cond = True
	for i in range(n):
		(c, x) = map(int, input().split())
		if cond:
			if c == 1:
				vl = h - y1
				if vl <= x:
					count += 1
				elif l > 0:
					l -= 1
					if l != 0:
						count += 1
					else:
						cond = False
				else:
					cond = False
			elif y2 >= x:
				count += 1
			elif l > 0:
				l -= 1
				if l != 0:
					count += 1
				else:
					cond = False
			else:
				cond = False
	print(count)


t = int(input())
for t in range(t):
	(n, h, y1, y2, l) = [int(i) for i in input().split()]
	duck = h - y1
	jump = y2
	count = 0
	flag = 1
	for i in range(n):
		(t, x) = [int(i) for i in input().split()]
		if t == 1 and flag == 1:
			if duck <= x:
				count += 1
			elif l > 1:
				count += 1
				l = l - 1
			else:
				flag = 0
				continue
		elif t == 2 and flag == 1:
			if jump >= x:
				count += 1
			elif l > 1:
				count += 1
				l = l - 1
			else:
				flag = 0
	print(count)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	count = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		if t == 1:
			if h - y1 > x:
				l -= 1
		elif y2 < x:
			l -= 1
		if l > 0:
			count += 1
	print(count)


t = int(input(''))
for _ in range(t):
	(n, height, duck, jump, life) = map(int, input().split())
	count = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		if t == 1:
			if x >= height - duck:
				pass
			else:
				life -= 1
		elif t == 2:
			if x <= jump:
				pass
			else:
				life -= 1
		else:
			pass
		if life > 0:
			count += 1
	print(count)


for i in range(int(input())):
	(n, height, duck, jump, life) = map(int, input().split())
	count = 0
	for z in range(n):
		(t, x) = map(int, input().split())
		if t == 1:
			if x < height - duck:
				if life > 0:
					life = life - 1
					if life != 0:
						count += 1
			elif life != 0:
				count += 1
		elif x > jump:
			if life > 0:
				life = life - 1
				if life != 0:
					count += 1
		elif life != 0:
			count += 1
	print(count)


for i in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	ba = []
	for i in range(n):
		(a, b) = map(int, input().split())
		ba.append((a, b))
	a = 0
	for i in ba:
		if i[0] == 1:
			if i[1] < h - y1:
				l -= 1
		if i[0] == 2:
			if i[1] > y2:
				l -= 1
		if l >= 1:
			a += 1
	print(a)


for _ in range(int(input())):
	(N, H, Y1, Y2, L) = map(int, input().split())
	answ = N
	duck = H - Y1
	done = False
	for i in range(N):
		(t, x) = map(int, input().split())
		if not done:
			if t == 1:
				if x < duck:
					L -= 1
			elif x > Y2:
				L -= 1
			if L == 0:
				answ = i
				done = True
	print(answ)


for t in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	a = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		if t == 1 and x < h - y1:
			l -= 1
		elif t == 2 and x > y2:
			l -= 1
		if l > 0:
			a += 1
	print(a)


T = int(input())
for _ in range(T):
	(n, h, y1, y2, l) = list(map(int, input().split()))
	cnt = 0
	for _ in range(n):
		(t, x) = list(map(int, input().split()))
		if l > 0:
			if t == 1:
				if h - y1 <= x:
					cnt += 1
				else:
					l -= 1
					cnt += 1 if l > 0 else 0
			elif y2 >= x:
				cnt += 1
			else:
				l -= 1
				cnt += 1 if l > 0 else 0
	print(cnt)


t = int(input())
for _ in range(t):
	(n, h, y1, y2, l) = map(int, input().split())
	barriers = []
	for _ in range(n):
		b = list(map(int, input().split()))
		barriers.append(b)
	duck = h - y1
	passed = 0
	for bar in barriers:
		if bar[0] == 1:
			if duck > bar[1]:
				l -= 1
			if l == 0:
				break
			else:
				passed += 1
		elif bar[0] == 2:
			if y2 < bar[1]:
				l -= 1
			if l == 0:
				break
			else:
				passed += 1
	print(passed)


t = int(input())
while t > 0:
	(n, h, y1, y2, l) = map(int, input().split())
	lst = []
	for i in range(n):
		(a, n) = map(int, input().split())
		lst.append([a, n])
	score = 0
	for lvl in range(len(lst)):
		if lst[lvl][0] == 1:
			if h - y1 <= lst[lvl][1]:
				score = score + 1
			elif l != 1:
				score = score + 1
				l = l - 1
			else:
				break
		elif y2 >= lst[lvl][1]:
			score = score + 1
		elif l != 1:
			score = score + 1
			l = l - 1
		else:
			break
	print(score)
	t = t - 1


for _ in range(int(input())):
	(n, h, du, j, f) = map(int, input().split())
	d = dict()
	for i in range(n):
		d[i] = list(map(int, input().split()))
	count = 0
	for i in d.keys():
		if d[i][0] == 2:
			if d[i][1] <= j:
				count += 1
			else:
				f -= 1
				if f < 1:
					break
				count += 1
		elif d[i][1] >= h - du:
			count += 1
		else:
			f -= 1
			if f < 1:
				break
			count += 1
	print(count)


t = input()
for c in range(0, int(t)):
	(n, h, y1, y2, l) = input().split()
	count = 0
	for y in range(0, int(n)):
		(t, x) = input().split()
		if int(l) == 0:
			pass
		elif int(t) == 1:
			if int(h) - int(y1) <= int(x):
				count = count + 1
			elif int(l) > 1:
				l = int(l) - 1
				count = count + 1
			else:
				l = 0
		elif int(y2) >= int(x):
			count = count + 1
		elif int(l) > 1:
			l = int(l) - 1
			count = count + 1
		else:
			l = 0
	print(count)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	ans = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		if l == 0:
			pass
		elif t == 1 and h - y1 <= x:
			ans += 1
		elif t == 2 and y2 >= x:
			ans += 1
		elif l > 1:
			l -= 1
			ans += 1
		else:
			l = 0
	print(ans)


for _ in range(int(input())):
	(N, H, Y1, Y2, L) = list(map(int, input().split()))
	ans = 0
	flag = False
	for _2 in range(N):
		(t, X) = list(map(int, input().split()))
		if flag:
			continue
		if t == 1:
			if X >= H - Y1:
				ans += 1
			elif L > 1:
				L -= 1
				ans += 1
			else:
				flag = True
		if t == 2:
			if X <= Y2:
				ans += 1
			elif L > 1:
				L -= 1
				ans += 1
			else:
				flag = True
	print(ans)


get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
for _ in range(get_int()):
	(N, H, Y1, Y2, L) = get_mint()
	Y1 = H - Y1
	barriers = [get_mint() for _ in range(N)]
	cnt = 0
	for (ti, Xi) in barriers:
		if ti == 2:
			if Xi > Y2:
				L -= 1
		elif Xi < Y1:
			L -= 1
		if L == 0:
			break
		cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	hLow = h - y1
	cnt = 0
	data = []
	for _ in range(n):
		(t, x) = map(int, input().split())
		if t == 1:
			if x < hLow:
				l -= 1
		elif x > y2:
			l -= 1
		if l >= 1:
			cnt += 1
	print(cnt)


t = int(input())
while t:
	t -= 1
	(n, h, y1, y2, l) = map(int, input().split())
	count = 0
	while n:
		n -= 1
		(t1, t2) = map(int, input().split())
		if t1 == 2:
			if t2 > y2:
				l -= 1
		elif h - y1 > t2:
			l -= 1
		if l >= 1:
			count += 1
	print(count)


for t in range(int(input())):
	(n, h, d, j, l) = map(int, input().split())
	can_go = True
	done = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		if can_go == True:
			if t == 1:
				if h - d > x:
					l -= 1
			elif j < x:
				l -= 1
			if l == 0:
				can_go = False
			else:
				done += 1
	print(done)


for i in range(int(input())):
	(n, H, Y1, Y2, L) = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append(list(list(map(int, input().split()))))
	p = 0
	for i in range(n):
		if l[i][0] == 1:
			if H - Y1 > l[i][1]:
				L -= 1
		elif Y2 < l[i][1]:
			L -= 1
		if L == 0:
			break
		p += 1
	print(p)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	a = []
	for i in range(n):
		(t, y) = map(int, input().split())
		a.append((t, y))
	p = 0
	for j in range(n):
		if a[j][0] == 1:
			if h - y1 > a[j][1]:
				l -= 1
		elif y2 < a[j][1]:
			l -= 1
		if l == 0:
			break
		p += 1
	print(p)


for _ in range(int(input())):
	(N, H, Y1, Y2, L) = map(int, input().split())
	l = []
	for i in range(N):
		(T, Y) = map(int, input().split())
		l.append((T, Y))
	p = 0
	for i in range(N):
		if l[i][0] == 1:
			if H - Y1 > l[i][1]:
				L -= 1
		elif Y2 < l[i][1]:
			L -= 1
		if L == 0:
			break
		p += 1
	print(p)


for a in range(int(input())):
	(N, H, Y1, Y2, L) = map(int, input().split())
	l = []
	num = 0
	for i in range(N):
		tpl = list(map(int, input().split()))
		l.append(tpl)
	for el in l:
		if L > 0 and el[0] == 1:
			if H - Y1 <= el[1]:
				num += 1
			elif L > 1:
				num += 1
				L -= 1
			else:
				break
		elif L > 0 and el[0] == 2:
			if Y2 >= el[1]:
				num += 1
			elif L > 1:
				num += 1
				L -= 1
			else:
				break
		else:
			break
	print(num)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().strip().split())
	a = []
	for __ in range(n):
		b = list(map(int, input().strip().split()))
		a.append(b)
	cntr = 0
	for i in a:
		if i[0] == 1:
			if h - y1 <= i[1]:
				cntr += 1
				continue
			elif l == 1:
				break
			else:
				cntr += 1
				l -= 1
		elif i[0] == 2:
			if y2 >= i[1]:
				cntr += 1
				continue
			elif l == 1:
				break
			else:
				cntr += 1
				l -= 1
	print(cntr)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	cnt = 0
	run = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		if run == 0:
			if t == 1:
				if x < h - y1:
					if l <= 1:
						run = 1
					else:
						l -= 1
			elif y2 < x:
				if l <= 1:
					run = 1
				else:
					l -= 1
			cnt += 1
	print(cnt - run)


for _ in range(int(input())):
	(n, h, y1, y2, l) = list(map(int, input().split()))
	t = []
	x = []
	for i in range(n):
		(a, b) = map(int, input().split())
		t.append(a)
		x.append(b)
	count = 0
	for i in range(n):
		if t[i] == 1:
			if h > x[i]:
				if h - y1 > x[i]:
					l = l - 1
					if l == 0:
						break
					else:
						count = count + 1
				else:
					count = count + 1
			else:
				count = count + 1
		elif y2 < x[i]:
			l = l - 1
			if l == 0:
				break
			else:
				count = count + 1
		else:
			count = count + 1
	print(count)


tests = int(input())
for i in range(tests):
	(n, h, a, b, l) = map(int, input().split())
	ans = 0
	for j in range(n):
		(t, x) = map(int, input().split())
		if l >= 1:
			if t == 1 and h - a > x:
				l -= 1
			if t == 2 and b < x:
				l -= 1
			if l >= 1:
				ans += 1
	print(ans)


T = int(input())
for i in range(T):
	(n, h, y1, y2, l) = map(int, input().split())
	x1 = []
	t1 = []
	for i in range(n):
		(t, x) = map(int, input().split())
		t1.append(t)
		x1.append(x)
	c = 0
	d = h - y1
	for i in range(n):
		if t1[i] == 2:
			if y2 < x1[i] and l > 1:
				c += 1
				l -= 1
			elif y2 >= x1[i] and l > 0:
				c += 1
			elif y2 < x1[i] and l == 1:
				l -= 1
		elif t1[i] == 1:
			if d > x1[i] and l > 1:
				c += 1
				l -= 1
			elif d <= x1[i] and l > 0:
				c += 1
			elif d > x1[i] and l == 1:
				l -= 1
	print(c)


t = int(input())
for _ in range(t):
	list1 = list(map(int, input().split()))
	duck = list1[1] - list1[2]
	count = 0
	for i in range(list1[0]):
		list2 = list(map(int, input().split()))
		if list2[0] == 2:
			if list2[1] > list1[3] and list1[4] > 1:
				count = count + 1
				list1[4] = list1[4] - 1
			elif list2[1] <= list1[3] and list1[4] > 0:
				count = count + 1
			elif list2[1] > list1[3] and list1[4] == 1:
				list1[4] = list1[4] - 1
		elif list2[0] == 1:
			if duck > list2[1] and list1[4] > 1:
				count = count + 1
				list1[4] = list1[4] - 1
			elif duck <= list2[1] and list1[4] > 0:
				count = count + 1
			elif duck > list2[1] and list1[4] == 1:
				list1[4] = list1[4] - 1
	print(count)


for i in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split(' '))
	(count, flag) = (0, 0)
	for i in range(n):
		(a, b) = map(int, input().split(' '))
		if flag == 0:
			if a == 1:
				if b < h - y1:
					if l <= 1:
						flag = 1
					else:
						l -= 1
			elif y2 < b:
				if l <= 1:
					flag = 1
				else:
					l -= 1
			count += 1
	print(count - flag)


t = int(input())
while t > 0:
	t -= 1
	(n, h, y1, y2, l) = list(map(int, input().split()))
	out = 0
	for i in range(n):
		(a, b) = list(map(int, input().split()))
		if l > 0:
			if a == 1:
				if b < h - y1:
					l -= 1
			elif a == 2:
				if b > y2:
					l -= 1
		if l > 0:
			out += 1
	print(out)


t = int(input())
for i in range(t):
	(n, h, y1, y2, l) = map(int, input().split())
	c = 0
	duck = h - y1
	jump = y2
	for j in range(n):
		(t, x) = map(int, input().split())
		if l > 0:
			if t == 1:
				if x < duck:
					l -= 1
			elif t == 2:
				if x > jump:
					l -= 1
		if l > 0:
			c += 1
	print(c)


for _ in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	list1 = []
	c = 0
	for i in range(n):
		(t, x) = map(int, input().split())
		list1.append((t, x))
	for i in list1:
		if i[0] == 1:
			if h - y1 <= i[1]:
				c += 1
			elif l:
				c += 1
				l = l - 1
				if l == 0:
					c = c - 1
					break
			elif not l:
				break
		elif y2 >= i[1]:
			c += 1
		elif l:
			c += 1
			l = l - 1
			if l == 0:
				c = c - 1
				break
		elif not l:
			break
	print(c)


T = int(input())
for x in range(T):
	(n, h, Y, y, ll) = map(int, input().split())
	l = []
	for i in range(n):
		(t, x) = map(int, input().strip().split())
		l.append((t, x))
	c = 0
	for i in l:
		if i[0] == 1:
			if h - Y <= i[1]:
				c += 1
			elif ll:
				c += 1
				ll -= 1
				if ll == 0:
					c -= 1
					break
			elif not ll:
				break
		elif y >= i[1]:
			c += 1
		elif ll:
			c += 1
			ll -= 1
			if ll == 0:
				c -= 1
				break
		elif not ll:
			break
	print(c)


def edward_barrier_pass(n, h, y1, y2, l, t_x):
	c = 0
	for i in range(n):
		if l == 0:
			break
		(ty, x) = (t_x[i][0], t_x[i][1])
		if ty == 1:
			e_h = h - y1
			if e_h > x:
				if l == 1:
					return c
				l -= 1
				c += 1
			else:
				c += 1
		elif y2 >= x:
			c += 1
		else:
			if l == 1:
				return c
			l -= 1
			c += 1
	return c
T = int(input())
for _ in range(T):
	t_x = list()
	(n, h, y1, y2, l) = list(map(int, input().split()))
	for i in range(n):
		t = list(map(int, input().split()))
		t_x.append(t)
	print(edward_barrier_pass(n, h, y1, y2, l, t_x))


for tc in range(int(input())):
	(n, h, y1, y2, l) = map(int, input().split())
	z = []
	for i in range(n):
		z.append(list(map(int, input().split())))
	i = 0
	while i < n:
		if z[i][0] == 1:
			if z[i][1] < h - y1:
				l -= 1
				if l < 1:
					break
				else:
					i += 1
			else:
				i += 1
		elif z[i][1] > y2:
			l -= 1
			if l < 1:
				break
			else:
				i += 1
		else:
			i += 1
	print(i)


T = int(input())
for i in range(0, T):
	(ba, he, du, ju, al) = input().split()
	ba = int(ba)
	he = int(he)
	du = int(du)
	ju = int(ju)
	al = int(al)
	du = max(0, he - du)
	for j in range(0, ba):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		if a == 2:
			if b > ju:
				al -= 1
		elif b < du:
			al -= 1
		if al == 0:
			he = j
			break
	else:
		he = j + 1
	for j in range(he, ba - 1):
		a = input()
	print(he)


for _ in range(int(input())):
	(N, H, Y1, Y2, L) = [int(s) for s in input().split()]
	Y1 = H - Y1
	K = 0
	for _ in range(N):
		if not L:
			input()
			continue
		(T, X) = input().split()
		X = int(X)
		if T == '1':
			if X < Y1:
				L -= 1
				if not L:
					continue
			K += 1
		else:
			if X > Y2:
				L -= 1
				if not L:
					continue
			K += 1
	print(K)


for _ in range(int(input())):
	(N, H, Y1, Y2, L) = map(int, input().split())
	ans = 0
	for i in range(N):
		(Ti, Xi) = map(int, input().split())
		if L == 0:
			continue
		if Ti == 1:
			if H - Y1 <= Xi and L != 0:
				ans += 1
			else:
				L -= 1
				if L == 0:
					continue
				ans += 1
		elif Ti == 2 and L != 0:
			if Y2 >= Xi and L != 0:
				ans += 1
			else:
				L -= 1
				if L == 0:
					continue
				ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = [int(x) for x in input().split()]
	c = 0
	for j in range(n[0]):
		a = [int(x) for x in input().split()]
		if n[4] != 0:
			if a[0] == 1:
				if n[1] - n[2] <= a[1]:
					c += 1
				else:
					n[4] = n[4] - 1
					if n[4] != 0:
						c += 1
			if a[0] == 2:
				if n[3] >= a[1]:
					c += 1
				else:
					n[4] = n[4] - 1
					if n[4] != 0:
						c += 1
	print(c)


case = int(input())
for i in range(case):
	(N, H, Y1, Y2, L) = list(map(int, input().split(' ')))
	duck = H - Y1
	jump = Y2
	ans = 0
	for j in range(N):
		(typ, val) = map(int, input().split(' '))
		if L > 0:
			if typ == 2:
				if val > jump:
					L -= 1
			elif typ == 1:
				if val < duck:
					L -= 1
		if L > 0:
			ans += 1
	print(ans)


t = int(input())
if t < 1 or t > 100:
	exit()
for i in range(t):
	(n, h, y1, y2, l) = map(int, input().split())
	count = 0
	if n < 1 or n > 1000 or h < 1 or (h > 1000) or (y1 < 1) or (y1 > h) or (y2 < 1) or (y2 > 1000) or (l < 1) or (l > n):
		exit
	for j in range(n):
		(a, b) = map(int, input().split())
		if a < 1 or a > 2 or b < 1 or (b > 1000):
			exit
		if l <= 0:
			continue
		if a == 1:
			duck = h - y1
			if duck > b:
				l = l - 1
			count = count + 1
		if a == 2:
			if b > y2:
				l = l - 1
			count += 1
	if l != 0:
		print(count)
	else:
		print(count - 1)


T = int(input())
for _ in range(T):
	(N, H, Y1, Y2, L) = map(int, input().strip().split())
	ans = 0
	for i in range(N):
		(t, X) = map(int, input().strip().split())
		if L >= 1:
			if t == 1:
				if H - Y1 <= X:
					ans += 1
				elif L >= 2:
					ans += 1
					L = L - 1
				else:
					L = L - 1
			elif Y2 >= X:
				ans += 1
			elif L >= 2:
				ans += 1
				L = L - 1
			else:
				L = L - 1
	print(ans)


t = int(input())
for j in range(t):
	(n, h, y1, y2, l) = map(int, input().split())
	count = 0
	a = [0] * n
	b = [0] * n
	for k in range(n):
		(a[k], b[k]) = map(int, input().split())
	for i in range(n):
		if a[i] == 1:
			if h - y1 <= b[i]:
				count += 1
			elif l > 1:
				l = l - 1
				count += 1
			else:
				break
		if a[i] == 2:
			if y2 >= b[i]:
				count += 1
			elif l > 1:
				l = l - 1
				count += 1
			else:
				break
	print(count)


test = int(input())
while test > 0:
	(n, h, y1, y2, l) = map(int, input().split())
	ans = 0
	t = [0] * n
	x = [0] * n
	for i in range(n):
		(t[i], x[i]) = map(int, input().split())
	for i in range(n):
		if t[i] == 1:
			if h - y1 <= x[i]:
				ans += 1
			elif l > 1:
				ans += 1
				l -= 1
			else:
				break
		elif y2 >= x[i]:
			ans += 1
		elif l > 1:
			ans += 1
			l -= 1
		else:
			break
	print(ans)
	test -= 1


t = int(input())
for i in range(t):
	(N, H, Y1, Y2, L) = list(map(int, input().split(' ')))
	B = []
	for i in range(N):
		B.append(tuple(map(int, input().split()[0:2])))
	count = 0
	for b in B:
		if b[0] == 1:
			if H - Y1 <= b[1]:
				count += 1
			elif L > 1:
				count += 1
				L -= 1
			else:
				break
		if b[0] == 2:
			if Y2 >= b[1]:
				count += 1
			elif L > 1:
				count += 1
				L -= 1
			else:
				break
	print(count)