You are given an array $a$ of $n$ integers. Find the number of pairs $(i, j)$ ($1 \le i < j \le n$) where the sum of $a_i + a_j$ is greater than or equal to $l$ and less than or equal to $r$ (that is, $l \le a_i + a_j \le r$).

For example, if $n = 3$, $a = [5, 1, 2]$, $l = 4$ and $r = 7$, then two pairs are suitable:

$i=1$ and $j=2$ ($4 \le 5 + 1 \le 7$);

$i=1$ and $j=3$ ($4 \le 5 + 2 \le 7$).


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

The first line of each test case contains three integers $n, l, r$ ($1 \le n \le 2 \cdot 10^5$, $1 \le l \le r \le 10^9$) — the length of the array and the limits on the sum in the pair.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).

It is guaranteed that the sum of $n$ overall test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, output a single integer — the number of index pairs $(i, j)$ ($i < j$), such that $l \le a_i + a_j \le r$.


-----Examples-----

Input
4
3 4 7
5 1 2
5 5 8
5 1 2 4 3
4 100 1000
1 1 1 1
5 9 13
2 5 5 1 1
Output
2
7
0
1


-----Note-----

None

Difficulty: EASY
Tags: Data structures

Sorting

Amortized analysis

Mathematics
Skill types: Amortized analysis

Sorting

Data structures

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, l, r) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	count = 0
	i = 0
	j = 0
	while i < n:
		n -= 1
		while i < n and a[i] + a[n] < l:
			i += 1
		while j < n and a[j] + a[n] <= r:
			j += 1
		count += min(j, n) - i
	print(count)


t = int(input())
for _ in range(t):
	(n, l, r) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	sortedlst = sorted(lst)
	lpoint = 0
	rpoint1 = n - 1
	total1 = 0
	while lpoint < rpoint1:
		if sortedlst[lpoint] + sortedlst[rpoint1] <= r:
			total1 += rpoint1 - lpoint
			lpoint += 1
		else:
			rpoint1 -= 1
	lpoint = 0
	rpoint2 = n - 1
	total2 = 0
	while lpoint < rpoint2:
		if sortedlst[lpoint] + sortedlst[rpoint2] <= l - 1:
			total2 += rpoint2 - lpoint
			lpoint += 1
		else:
			rpoint2 -= 1
	print(total1 - total2)


from bisect import *
for _ in range(int(input())):
	(n, b, c) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	l.sort()
	val = 0
	for i in range(n):
		a1 = c - l[i]
		a2 = b - l[i]
		lo = bisect_left(l, a2, 1 + i, n)
		hi = bisect_right(l, a1, i + 1, n)
		val += hi - lo
	print(val)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, l, r) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	cnt = 0
	b = a.copy()
	b.sort()
	ans = 0
	for i in a:
		if 2 * i >= l and 2 * i <= r:
			cnt += 1
			ans -= 1
		p1 = bsl(b, l - i)
		p2 = bsr(b, r - i)
		if p2 < p1 or p1 == n or p2 == 0:
			continue
		ans += p2 - p1
	print(ans // 2)


for _ in range(int(input())):
	(n, l, r) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	arr.sort()
	i = 0
	j = n - 1
	c1 = 0
	while i < j:
		if arr[i] + arr[j] <= r:
			i += 1
		else:
			c1 += j - i
			j -= 1
	i = 0
	j = n - 1
	c2 = 0
	while i < j:
		if arr[i] + arr[j] >= l:
			j -= 1
		else:
			c2 += j - i
			i += 1
	ans = n * (n - 1) // 2 - c1 - c2
	print(ans)


import sys
t = int(sys.stdin.readline())
while t:
	t -= 1
	(n, l, r) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	arr.sort()
	(ans, A, B) = (0, 0, 0)
	cnt = 0
	for i in range(n):
		(lo, hi) = (i + 1, n - 1)
		ans = 0
		while lo <= hi:
			mid = lo + (hi - lo) // 2
			if arr[mid] + arr[i] <= r:
				ans = mid
				lo = mid + 1
			else:
				hi = mid - 1
		if ans != 0:
			A += ans - i
		ans = 0
		(lo, hi) = (i + 1, n - 1)
		while lo <= hi:
			mid = lo + (hi - lo) // 2
			if arr[mid] + arr[i] <= l - 1:
				ans = mid
				lo = mid + 1
			else:
				hi = mid - 1
		if ans != 0:
			B += ans - i
		cnt += A - B
		(A, B) = (0, 0)
	print(cnt)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left, bisect
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	p = sorted(list(map(int, input().split())))
	c = 0
	for i in range(n):
		if p[i] < r:
			a = bisect_left(p, l - p[i])
			b = bisect_right(p, r - p[i])
			(s, e) = (-1, -1)
			if a < n and p[a] + p[i] >= l and (p[a] + p[i] <= r):
				s = a
			elif a + 1 < n and p[a + 1] + p[i] >= l and (p[a + 1] + p[i] <= r):
				s = a + 1
			elif a - 1 >= 0 and p[a - 1] + p[i] >= l and (p[a - 1] + p[i] <= r):
				s = a - 1
			if b < n and p[b] + p[i] >= l and (p[b] + p[i] <= r):
				e = b
			elif b + 1 < n and p[b + 1] + p[i] >= l and (p[b + 1] + p[i] <= r):
				e = b + 1
			elif b - 1 >= 0 and p[b - 1] + p[i] >= l and (p[b - 1] + p[i] <= r):
				e = b - 1
			if s != -1 and e != -1 and (s <= e):
				s = max(s, i)
				e = max(e, i)
				if i >= s and i <= e:
					c += e - s
				else:
					c += e - s + 1
	print(c)


def findPairsl(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] < x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result

def findPairsr(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] <= x:
			result += r - l
			l += 1
		else:
			r -= 1
	return n * (n - 1) // 2 - result
t = int(input())
for _ in range(t):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = n * (n - 1) // 2
	ans -= findPairsl(arr, n, l)
	ans -= findPairsr(arr, n, r)
	print(ans)


tests = int(input())

def solve(a, n, k):
	i = 0
	temp = 0
	for j in range(n - 1, -1, -1):
		while a[i] + a[j] <= k and i < j:
			i += 1
		if i <= j:
			temp += i
		else:
			temp += j
	return temp
for _ in range(tests):
	(n, l, r) = map(int, input().split())
	test = list(map(int, input().split()))
	test.sort()
	ans = solve(test, n, r) - solve(test, n, l - 1)
	print(ans)


def count_r(x, a, b):
	x.sort()
	output = [0] * len(x)
	output2 = [0] * len(x)
	(i, j) = (0, len(x) - 1)
	while i - j <= 0:
		if x[i] + x[j] >= a:
			output[j] = i
			j -= 1
		else:
			output[i] = j + 1
			i += 1
	(i, j) = (0, len(x) - 1)
	while i - j <= 0:
		if x[i] + x[j] <= b:
			output2[i] = j
			i += 1
		else:
			output2[j] = i - 1
			j -= 1
	answer = [o2 - o + 1 - (o <= i <= o2) for (i, (o, o2)) in enumerate(zip(output, output2))]
	return sum(answer) // 2
t = int(input())
while t:
	(n, a, b) = map(int, input().split())
	li = list(map(int, input().split()))
	print(count_r(li, a, b))
	t = t - 1


import bisect
import bisect
t = int(input())
while t:
	(n, l, r) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	ans = 0
	a.sort()
	for i in range(n):
		mini = l - a[i]
		maxi = r - a[i]
		up = bisect.bisect_right(a, maxi, 0, 0 + i)
		low = bisect.bisect_left(a, mini, 0, 0 + i)
		ans += up - low
	print(abs(ans))
	t -= 1


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		(n, l, r) = li()
		a = arr(sorted(li()))
		c = 0
		i = 0
		j = n - 1
		while i < j:
			if a[i] + a[j] > r:
				j -= 1
			elif a[i] + a[j] < l:
				i += 1
			else:
				c += j - bl(a, l - a[i], i + 1) + 1
				i += 1
		print(c)
solve()


for _ in range(int(input())):
	(n, l, r) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	arr.sort()
	ans = 0
	for i in range(n - 1):
		if r - arr[i] >= arr[i]:
			s1 = i + 1
			e1 = n - 1
			val1 = -1
			while s1 <= e1:
				mid1 = s1 + (e1 - s1) // 2
				if arr[mid1] >= l - arr[i]:
					e1 = mid1 - 1
					val1 = mid1
				else:
					s1 = mid1 + 1
			if val1 == -1:
				continue
			else:
				s2 = i + 1
				e2 = n - 1
				val2 = -1
				while s2 <= e2:
					mid1 = s2 + (e2 - s2) // 2
					if arr[mid1] <= r - arr[i]:
						s2 = mid1 + 1
						val2 = mid1
					else:
						e2 = mid1 - 1
				if val2 != -1:
					ans += val2 - val1 + 1
	print(ans)


import os
import sys
import bisect

def main():
	fastReadInt = sys.stdin.buffer.readline

	def fastReadStr():
		return sys.stdin.buffer.readline().decode('utf-8').strip()

	def fastWrite(ans):
		return sys.stdout.buffer.write(str(str(ans) + '\n').encode('utf-8'))

	def fastWriteList(ans):
		return sys.stdout.buffer.write(str(' '.join(map(str, ans)) + '\n').encode('utf-8'))
	DEBUG = 'DEBUG' in os.environ

	def debug(*args):
		if DEBUG:
			print('>', *args)

	def find_le(a, x):
		i = bisect.bisect_right(a, x)
		if i:
			return i - 1
		return -1

	def find_ge(a, x):
		i = bisect.bisect_left(a, x)
		if i != len(a):
			return i
		return -1

	def solution(n, l, r, value):
		debug('')
		value.sort()
		debug(n, l, r, value)
		res = 0
		for ni in range(0, len(value)):
			n = value[ni]
			upper = find_le(value, r - n)
			lower = find_ge(value, l - n)
			if upper != -1 and lower != -1:
				debug(ni, [lower, upper])
				res += upper - lower + 1
				if ni >= lower and ni <= upper:
					res -= 1
		fastWrite(res // 2)
	for t in range(int(fastReadInt())):
		nlr = list(map(int, fastReadInt().split()))
		n = nlr[0]
		l = nlr[1]
		r = nlr[2]
		solution(n, l, r, list(map(int, fastReadInt().split())))
main()


def count_ranged_pairs(x, a, b):
	x.sort()
	output = [0] * len(x)
	output2 = [0] * len(x)
	(i, j) = (0, len(x) - 1)
	while i - j <= 0:
		if x[i] + x[j] >= a:
			output[j] = i
			j -= 1
		else:
			output[i] = j + 1
			i += 1
	(i, j) = (0, len(x) - 1)
	while i - j <= 0:
		if x[i] + x[j] <= b:
			output2[i] = j
			i += 1
		else:
			output2[j] = i - 1
			j -= 1
	answer = [o2 - o + 1 - (o <= i <= o2) for (i, (o, o2)) in enumerate(zip(output, output2))]
	return int(sum(answer) / 2)

def main():
	t = int(input())
	while t:
		(n, l, r) = map(int, input().split())
		arr = list(map(int, input().split()))
		print(count_ranged_pairs(arr, l, r))
		t -= 1
	return
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
from itertools import accumulate, permutations
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, l, r) = li()
	l1 = sorted(li())
	ans = 0
	for i in range(n):
		if l1[i] > r:
			continue
		else:
			temp1 = n - bl(l1, l - l1[i])
			temp2 = n - br(l1, r - l1[i])
			ans += temp1 - temp2
	for i in range(n):
		if l <= 2 * l1[i] <= r:
			ans -= 1
	print(ans // 2)


def xx(a, n):
	c = 0
	i = 0
	j = len(a) - 1
	while i < j:
		if a[i] + a[j] >= n:
			j -= 1
		else:
			c += j - i
			i += 1
	return c
from sys import stdin, stdout
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	c = 0
	a = list(map(int, input().split()))
	a.sort()
	a1 = xx(a, l)
	a2 = xx(a, r + 1)
	print(a2 - a1)


takeArr = lambda : list(map(int, input().split()))
import sys
sys.setrecursionlimit(10 ** 6)

def find(arr, i, j, x):
	ans = 0
	while i < j:
		if arr[i] + arr[j] < x:
			ans += j - i
			i += 1
		else:
			j -= 1
	return ans
for t in range(int(input())):
	(n, l, r) = takeArr()
	arr = takeArr()
	arr.sort()
	ans = find(arr, 0, n - 1, r + 1) - find(arr, 0, n - 1, l)
	print(ans)


def UpperBound(A, key):
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] >= key:
			right = middle
		else:
			left = middle
	return right

def DownBound(A, key):
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] <= key:
			left = middle
		else:
			right = middle
	return left

def sol():
	(n, l, r) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	ans = 0
	for i in range(n):
		left = UpperBound(a, l - a[i])
		right = DownBound(a, r - a[i])
		if right >= left:
			ans += right - left + 1
			if left <= i <= right:
				ans -= 1
	return ans // 2

def main():
	for i in range(int(input())):
		print(sol())
main()


import sys
import math
import collections
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

def bi1(idx):
	left = idx + 1
	right = n - 1
	ans = 9999999
	while left <= right:
		mid = (left + right) // 2
		if L[idx] + L[mid] <= r:
			left = mid + 1
			ans = mid
		else:
			right = mid - 1
	return ans

def bi2(idx):
	left = idx + 1
	right = n - 1
	ans = 9999999
	while left <= right:
		mid = (left + right) // 2
		if l <= L[idx] + L[mid]:
			right = mid - 1
			ans = mid
		else:
			left = mid + 1
	return ans
for _ in range(int(sys.stdin.readline())):
	(n, l, r) = map(int, sys.stdin.readline().split())
	L = list(map(int, sys.stdin.readline().split()))
	L.sort()
	anss = 0
	for i in range(n):
		a = bi1(i)
		b = bi2(i)
		if a == 9999999 or b == 9999999:
			continue
		anss += a - b + 1
	print(anss)


from bisect import bisect_right, bisect_left
t = int(input())
for _ in range(t):
	(n, l, r) = map(int, input().split())
	nums = sorted(list(map(int, input().split())))
	ans = 0
	while nums:
		num = nums.pop()
		left = l - num
		right = r - num
		cnt = 0
		cnt += bisect_right(nums, right) - bisect_left(nums, left)
		ans += cnt
	print(ans)


R = lambda : map(int, input().split())
t = list(R())[0]
while t:
	t -= 1
	(n, l, r) = R()
	a = sorted(R())
	i = j = q = 0
	while i < n:
		n -= 1
		while i < n and a[i] + a[n] < l:
			i += 1
		while j < n and a[j] + a[n] <= r:
			j += 1
		q += min(j, n) - i
	print(q)


def count_pairs(arr, target):
	count = 0
	n = len(arr)
	l = 0
	r = len(arr) - 1
	while l < r:
		if arr[l] + arr[r] > target:
			count += r - l
			r -= 1
		else:
			l += 1
	return n * (n - 1) / 2 - count
for _ in range(int(input())):
	(n, low, high) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	a = count_pairs(arr, high)
	b = count_pairs(arr, low - 1)
	print(int(a - b))


t = int(input())
for i in range(t):
	(n, l, r) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	kq = 0
	u = n
	v = n - 1
	for j in range(0, n - 1):
		u = max(u, j + 1)
		while v > j and a[j] + a[v] > r:
			v -= 1
		if v == j:
			break
		while u - 1 > j and a[j] + a[u - 1] >= l:
			u -= 1
		if u > v:
			continue
		kq += v - u + 1
	print(kq)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	low = 0
	high = n - 1
	(c1, c2) = (0, 0)
	while low < high:
		if arr[low] + arr[high] < l:
			c1 += high - low
			low += 1
		else:
			high -= 1
	low = 0
	high = n - 1
	while low < high:
		if arr[low] + arr[high] > r:
			c2 += high - low
			high -= 1
		else:
			low += 1
	total = n * (n - 1) // 2
	print(total - c1 - c2)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	t = n - 1
	p = n - 1
	ans = 0
	for j in range(n):
		i = a[j]
		while i + a[p] > r and p >= 0:
			p -= 1
		while i + a[t] >= l and t >= 0:
			t -= 1
		if p > j:
			ans += p - max(t, j)
		else:
			break
	print(ans)


for t in range(int(input())):
	(n, A, B) = map(int, input().split())
	a = list(map(int, input().split()))
	p = 0
	a.sort()
	for i in range(n - 1):
		(l, h) = (i + 1, n - 1)
		m = -1
		while l <= h:
			m = (l + h) // 2
			s = a[m] + a[i]
			if s >= A and s <= B:
				break
			elif s > B:
				h = m - 1
			else:
				l = m + 1
		p1 = -1
		(h1, l1) = (m, m)
		while l <= h1:
			p1 = (l + h1) // 2
			s = a[p1] + a[i]
			if s >= A and s <= B:
				h1 = p1 - 1
			elif s > B:
				break
			else:
				l = p1 + 1
		p2 = -1
		while l1 <= h:
			p2 = (l1 + h) // 2
			s = a[p2] + a[i]
			if s >= A and s <= B:
				l1 = p2 + 1
			elif s > B:
				h = p2 - 1
			else:
				break
		if p1 > -1 and p1 < n and (p1 <= p2) and (a[p1] + a[i] < A):
			p1 += 1
		if p2 > -1 and p2 >= 0 and (p1 <= p2) and (a[p2] + a[i] > B):
			p2 -= 1
		if p2 - p1 >= 0 and p1 > -1 and (p2 > -1):
			p += p2 - p1 + 1
	print(p)


import io
import os
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappush, heappop, heapify
from math import gcd, inf

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def solve(N, L, R, A):
	sl = SortedList()
	ans = 0
	for x in A:
		i = sl.bisect_left(L - x)
		j = sl.bisect_right(R - x)
		ans += j - i
		sl.add(x)
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, L, R) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, L, R, A)
	print(ans)


from sys import stdin
from bisect import bisect_right, bisect_left, bisect
for _ in range(int(stdin.readline())):
	(n, l, r) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	arr.sort()
	ans = 0
	for i in range(n):
		x = l - arr[i]
		y = r - arr[i]
		k = bisect_left(arr, x, i + 1, n)
		j = bisect_right(arr, y, i + 1, n)
		ans += j - k
	print(ans)


def countrangesum(n, num, lower, upper):
	if not n - 1:
		return 0
	pairs = 0
	num = sorted(num)
	start = 0
	high = n - 1
	while num[start] + num[-1] < lower:
		start += 1
		if start == n - 1:
			return pairs
	low = start + 1
	while num[start] + num[low] < lower:
		low += 1
	while high > start:
		if low <= start:
			low = start + 1
		while num[high] + num[start] > upper and high > start:
			high -= 1
		while num[low] + num[start] >= lower:
			low -= 1
			if low == start:
				break
		pairs += high - low
		start += 1
	return pairs
T = int(input())
for _ in range(T):
	(n, lower, upper) = map(int, input().split())
	num = list(map(int, input().split()))
	print(countrangesum(n, num, lower, upper))


for t in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	i = 0
	low = n - 1
	high = n - 1
	while i < high:
		low = max(i, low)
		while low > i and a[i] + a[low] >= l:
			low -= 1
		while high > low and a[i] + a[high] > r:
			high -= 1
		ans += high - low
		i += 1
	print(ans)


t = int(input())

def count(a, maximum):
	j = len(a) - 1
	c = 0
	for (i, val) in enumerate(a):
		while j > i and a[i] + a[j] > maximum:
			j = j - 1
		c += max(j - i, 0)
	return c
for _ in range(t):
	(n, l, r) = map(lambda x: int(x), input().split())
	arr = list(map(lambda x: int(x), input().split()))
	arr.sort()
	print(count(arr, r) - count(arr, l - 1))


list_ans = []
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list1.sort()
	i = j = 0
	ans = 0
	while i < n:
		n -= 1
		while i < n and list1[i] + list1[n] < l:
			i += 1
		while j < n and list1[j] + list1[n] <= r:
			j += 1
		ans += min(n, j) - i
	list_ans.append(ans)
for item in list_ans:
	print(item)


from bisect import bisect_left as bl, bisect_right as br
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = sorted(map(int, input().split()))
	su = 0
	for i in range(n):
		(up, lo) = (r - a[i], l - a[i])
		su += max(0, br(a, up) - max(i + 1, bl(a, lo)))
	print(su)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	i = 0
	lo = n - 1
	hi = n - 1
	while i < hi:
		lo = max(i, lo)
		while lo > i and a[i] + a[lo] >= l:
			lo = lo - 1
		while hi > lo and a[i] + a[hi] > r:
			hi = hi - 1
		c += hi - lo
		i += 1
	print(c)


import sys
from sys import stdin, stdout
(input, print) = (stdin.readline, stdout.write)
from collections import OrderedDict, defaultdict
import bisect
import math
t = int(input())
while t > 0:
	t -= 1
	(n, l, r) = [int(x) for x in input().split()]
	a = [*map(int, input().split())]
	a.sort()
	res = 0
	for i in range(n):
		x = a[i]
		L = bisect.bisect_left(a, l - x, i + 1, n)
		R = bisect.bisect_left(a, r - x + 1) - 1
		if L == n or x + a[R] < l:
			continue
		res += max(0, R - L + 1)
	print(str(res))
	print('\n')


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import copy
from itertools import combinations
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from collections import defaultdict
for _ in range(int(input())):
	(n, l, r) = get_ints()
	a = get_array()
	a.sort()
	ans = 0
	for i in range(len(a)):
		ll = l - a[i]
		ul = r - a[i]
		ind1 = bisect.bisect_right(a, ul)
		ind2 = bisect.bisect_left(a, ll)
		ind1 -= 1
		if ind1 <= i:
			continue
		ind2 = bisect.bisect_left(a, ll)
		if ind2 <= i:
			ind2 = min(i + 1, ind1)
		if ind1 - ind2 + 1 >= 0:
			ans += ind1 - ind2 + 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from bisect import *

def main():
	for _ in range(int(input())):
		(n, l, r) = map(int, input().split())
		a = sorted(map(int, input().split()))
		ans = 0
		for i in range(n):
			y = bisect_left(a, l - a[i])
			z = bisect_right(a, r - a[i])
			ans += max(0, z - y - (i >= y and i < z))
		print(ans // 2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict, Counter
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

def st():
	return input().strip()

def stf():
	return file.readline().strip()

def read():
	return list(map(int, input().strip().split()))

def readf():
	return list(map(int, file.readline().strip().split()))

def f(arr, x):
	n = len(arr)
	(i, j) = (0, n - 1)
	ans = 0
	while i < j:
		if arr[i] + arr[j] < x:
			i += 1
			ans += j - i + 1
		else:
			j -= 1
	return ans

def solve():
	for _ in range(nin()):
		(n, l, r) = read()
		arr = read()
		arr.sort()
		ans_.append(f(arr, r + 1) - f(arr, l))
solve()
for i in ans_:
	print(i)


from sys import stdin
t = int(stdin.readline())

def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	global l
	global r
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	for ia in range(i, mid + 1):
		p1 = j
		p2 = right
		a1 = -1
		a2 = -1
		while p1 <= p2:
			m = (p1 + p2) // 2
			if arr[m] + arr[ia] < l:
				p1 = m + 1
			else:
				a1 = m
				p2 = m - 1
		p1 = j
		p2 = right
		while p1 <= p2:
			m = (p1 + p2) // 2
			if arr[m] + arr[ia] > r:
				p2 = m - 1
			else:
				a2 = m
				p1 = m + 1
		if a1 != -1 and a2 != -1:
			if a2 - a1 >= 0:
				inv_count += a2 - a1 + 1
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count
while t:
	global l
	global r
	(n, l, r) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	print(mergeSort(a, n))
	t -= 1


import bisect
t = int(input())
for i in range(t):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	i = 0
	for el in a:
		ind1 = bisect.bisect_left(a, l - el, i)
		ind2 = bisect.bisect_right(a, r - el, i)
		temp = ind2 - ind1
		if ind1 <= i < ind2:
			temp -= 1
		ans += max(temp, 0)
		i += 1
	print(ans)


import sys
from bisect import bisect_left, bisect_right
read_line = lambda : sys.stdin.readline().strip()
read_intmap = lambda : map(int, read_line().split())

def testCase():
	(n, l, r) = read_intmap()
	a = sorted(read_intmap())
	ans = 0
	(i, j) = (0, n - 1)
	for j in range(n - 1, 0, -1):
		v = a[j]
		tr = r - v
		tl = l - v
		ir = bisect_right(a, tr, hi=j)
		il = bisect_left(a, tl, hi=j)
		ans += ir - il
	print(ans)
t = 1
t = int(input())
for i in range(t):
	testCase()


for _ in range(int(input())):
	(n, l, r) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	(low, high) = (n - 1, n - 1)
	i = 0
	while i < high:
		low = max(i, low)
		while low > i and a[i] + a[low] >= l:
			low -= 1
		while high > low and a[i] + a[high] > r:
			high -= 1
		c += high - low
		i += 1
	print(c)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10 ** 16
md = 998244353

def cnt(lim):
	j = n - 1
	res = 0
	for (i, a) in enumerate(aa):
		while j >= 0 and aa[j] + a > lim:
			j -= 1
		if j <= i:
			break
		res += j - i
	return res
for testcase in range(II()):
	(n, l, r) = LI()
	aa = LI()
	aa.sort()
	ans = cnt(r) - cnt(l - 1)
	print(ans)


def lessthan(a, end):
	i = 0
	j = len(a) - 1
	c = 0
	while i < j:
		k = a[i] + a[j]
		if k < end:
			c += j - i
			i += 1
		else:
			j -= 1
	return c
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	a.sort()
	a1 = lessthan(a, l)
	a2 = lessthan(a, r + 1)
	print(a2 - a1)


T = int(input())
frange = range
fprint = print
fint = int
finput = input
for i in frange(T):
	ans = 0
	(n, l, r) = map(fint, finput().split())
	arr = list(map(int, finput().split()))
	arr.sort()
	ans = 0
	i = 0
	j = 0
	while i < n:
		n -= 1
		while i < n and arr[i] + arr[n] < l:
			i += 1
		while j < n and arr[j] + arr[n] <= r:
			j += 1
		ans += min(j, n) - i
	fprint(ans)


from bisect import bisect_left as bl, bisect_right as br
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	for i in a:
		ans += br(a, r - i) - bl(a, l - i)
		if i + i in range(l, r + 1):
			ans -= 1
	print(ans // 2)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	i = j = count = 0
	while i < n:
		n -= 1
		while i < n and a[i] + a[n] < l:
			i += 1
		while j < n and a[j] + a[n] <= r:
			j += 1
		count += min(j, n) - i
	print(count)


import bisect
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = 0
	arr.sort()
	for i in range(n):
		lo = bisect.bisect_left(arr, l - arr[i])
		hi = bisect.bisect_right(arr, r - arr[i])
		(hi, lo) = (max(hi, i + 1), max(lo, i + 1))
		ans += hi - lo
	print(ans)


import bisect

def pairs(arr, l, r, n):
	count = 0
	arr.sort()
	ans = 0
	for i in range(n):
		a = arr[i]
		if arr[i] > r:
			return ans
		b = l - arr[i]
		c = r - arr[i]
		leftbisect = bisect.bisect_left(arr, b)
		rightbisect = bisect.bisect_right(arr, c)
		if leftbisect > i and rightbisect > i:
			ans += abs(rightbisect - leftbisect)
		elif leftbisect <= i and rightbisect > i:
			ans += rightbisect - i - 1
	return ans
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = [int(arr) for arr in input().split()]
	print(pairs(arr, l, r, n))


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def ispali(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def cal(arr, x):
	i = 0
	j = len(arr) - 1
	cnt = 0
	while i < j:
		if arr[j] + arr[i] <= x:
			cnt += j - i
			i += 1
		else:
			j -= 1
	return cnt

def main():
	ans = ''
	for _ in range(ii()):
		(n, l, r) = mi()
		arr = sorted(li())
		res = cal(arr, r) - cal(arr, l - 1)
		ans += str(res) + '\n'
	print(ans)
main()


import bisect
t = int(input())
for i in range(t):
	q = input().split()
	n = int(q[0])
	l = int(q[1])
	r = int(q[2])
	a = input().split()
	for j in range(n):
		a[j] = int(a[j])
	a.sort()
	ans = 0
	for j in range(n - 1):
		li = bisect.bisect_left(a, l - a[j], lo=j + 1, hi=len(a))
		ri = bisect.bisect_right(a, r - a[j], lo=j + 1, hi=len(a))
		ans += ri - li
	print(ans)


t = int(input())

def solve(k):
	j = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		while a[j] + a[i] <= k and j < i:
			j += 1
		if j <= i:
			temp += j
		else:
			temp += i
	return temp
while t > 0:
	t -= 1
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	print(solve(r) - solve(l - 1))


for _ in range(int(input())):
	(n, l, r) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	(low, high) = (n - 1, n - 1)
	idx = 0
	while idx < high:
		low = max(idx, low)
		while low > idx and a[idx] + a[low] >= l:
			low -= 1
		while high > low and a[idx] + a[high] > r:
			high -= 1
		ans += high - low
		idx += 1
	print(ans)


import bisect
from collections import Counter

def main(a, l, r):
	n = len(a)
	if n < 2:
		return 0
	a = sorted(a)
	i = 0
	j = len(a) - 1
	ans1 = 0
	while j > i:
		if a[j] + a[i] >= l:
			j -= 1
		else:
			ans1 += j - i
			i += 1
	ans2 = 0
	i = 0
	j = len(a) - 1
	while j > i:
		if a[j] + a[i] <= r:
			i += 1
		else:
			ans2 += j - i
			j -= 1
	return int(n * (n - 1) / 2 - (ans1 + ans2))
t = int(input())
outputs = []
for _ in range(t):
	(n, l, r) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	output = main(arr, l, r)
	outputs.append(output)
for o in outputs:
	print(o)


import bisect
t = int(input())
while t > 0:
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 0
	for i in range(len(arr)):
		ll = bisect.bisect_left(arr, l - arr[i], i + 1, n)
		rr = bisect.bisect_right(arr, r - arr[i], i + 1, n)
		ans += rr - ll
	print(ans)
	t -= 1


import math
t = int(input())
for _ in range(t):
	(n, l, r) = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	arr.sort()
	arr_0 = 0
	arr_1 = n - 1
	count2 = 0
	count = 0
	while arr_0 < arr_1:
		if arr[arr_0] + arr[arr_1] <= r:
			count = count + (arr_1 - arr_0)
			arr_0 += 1
		else:
			arr_1 -= 1
	arr_0 = 0
	arr_1 = n - 1
	while arr_0 < arr_1:
		if arr[arr_0] + arr[arr_1] <= l - 1:
			count2 = count2 + (arr_1 - arr_0)
			arr_0 += 1
		else:
			arr_1 -= 1
	print(-count2 + count)


def solve():
	(n, l, r) = map(int, input().split())
	vrsta = list(map(int, input().split()))
	vrsta.sort()
	out = 0
	import bisect
	for (index, x) in enumerate(vrsta[:-1]):
		i = bisect.bisect_left(vrsta, l - x)
		j = bisect.bisect_right(vrsta, r - x)
		i = max(index + 1, i)
		out += max(j - i, 0)
	return out
t = int(input())
for _ in range(t):
	print(solve())


def countGreater(arr, o, n, k):
	l = o
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

def countsmaller(arr, o, n, k):
	l = o
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] <= k:
			leftGreater = m
			l = m + 1
		else:
			r = m - 1
	if leftGreater - o + 1 > N - o:
		return 0
	else:
		return leftGreater - o + 1
for _ in range(int(input())):
	(N, L, R) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	A.sort()
	c = 0
	for i in range(N - 1):
		if A[i] < R:
			t = countGreater(A, i + 1, N, L - A[i])
			s = countsmaller(A, i + 1, N, R - A[i])
			if s + t > N - i - 1:
				c += s + t - N + i + 1
	print(c)


def solve(x, a, b):
	x.sort()
	output = [0] * len(x)
	output2 = [0] * len(x)
	(i, j) = (0, len(x) - 1)
	while i - j <= 0:
		if x[i] + x[j] >= a:
			output[j] = i
			j -= 1
		else:
			output[i] = j + 1
			i += 1
	(i, j) = (0, len(x) - 1)
	while i - j <= 0:
		if x[i] + x[j] <= b:
			output2[i] = j
			i += 1
		else:
			output2[j] = i - 1
			j -= 1
	answer = [o2 - o + 1 - (o <= i <= o2) for (i, (o, o2)) in enumerate(zip(output, output2))]
	return sum(answer) // 2
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = solve(a, l, r)
	print(ans)


def findPair(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] < x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 0
	ans += findPair(arr, n, r + 1)
	ans -= findPair(arr, n, l)
	print(ans)


for i in range(int(input())):
	(n, l, r) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()

	def pairs(m):
		(x, y) = (0, n - 1)
		ans = 0
		while x < y:
			if a[x] + a[y] < m:
				ans += y - x
				x += 1
			else:
				y -= 1
		return ans
	print(pairs(r + 1) - pairs(l))


t = int(input())

def solve():
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()

	def binMax(start, x):
		left = start
		right = n - 1
		ans = -1
		while left <= right:
			mid = left + (right - left) // 2
			if arr[mid] + x > r:
				right = mid - 1
			elif arr[mid] + x < l:
				left = mid + 1
			else:
				ans = max(ans, mid)
				left = mid + 1
		return ans

	def binMin(start, x):
		left = start
		right = n - 1
		ans = 99999999999999
		while left <= right:
			mid = left + (right - left) // 2
			if arr[mid] + x > r:
				right = mid - 1
			elif arr[mid] + x < l:
				left = mid + 1
			else:
				ans = min(ans, mid)
				right = mid - 1
		return ans
	ans = 0
	for i in range(len(arr) - 1):
		minIndex = binMin(i + 1, arr[i])
		maxIndex = binMax(i + 1, arr[i])
		if maxIndex == -1:
			continue
		ans += maxIndex - minIndex + 1
	print(ans)
for i in range(t):
	solve()


def find_solution_of_sub_problem(a, x):
	result = 0
	left = 0
	right = len(arr) - 1
	while left < right:
		if a[left] + a[right] <= x:
			result += right - left
			left += 1
		else:
			right -= 1
	return result
try:
	for _ in range(int(input())):
		(n, l, r) = map(int, input().split())
		arr = list(map(int, input().split()))
		arr.sort()
		ans1 = find_solution_of_sub_problem(arr, r)
		ans2 = find_solution_of_sub_problem(arr, l - 1)
		print(abs(ans1 - ans2))
except e:
	pass


def pairs_in_range(l, r, nums):
	nums.sort()
	n = len(nums)
	(left, right, res) = (0, 0, 0)
	while n:
		n -= 1
		while left < n and nums[left] + nums[n] < l:
			left += 1
		while right < n and nums[right] + nums[n] <= r:
			right += 1
		res += min(right, n) - min(left, n)
	return res
R = lambda : map(int, input().split())
(test_cases,) = R()
for test_case in range(test_cases):
	(n, left, right) = R()
	arr = list(R())
	print(pairs_in_range(left, right, arr))


for t in range(int(input())):
	(n, l, r) = map(int, input().split())
	lis = list(map(int, input().split()))
	lis.sort()
	import bisect
	cnt = 0
	for i in range(n):
		a = bisect.bisect_left(lis, l - lis[i])
		b = bisect.bisect_right(lis, r - lis[i])
		if b == n or lis[b] + lis[i] > r:
			b -= 1
		cnt += b - a + 1
		if a <= i and i <= b:
			cnt -= 1
	print(cnt // 2)


from bisect import bisect_left
from bisect import bisect_right
for _ in range(int(input())):
	(n, l, r) = map(int, input().strip().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	ans = 0
	for i in range(len(a)):
		temp = a[i]
		lr = bisect_left(a, l - temp, lo=i + 1)
		rr = bisect_right(a, r - temp, lo=i + 1)
		ans += rr - lr
	print(ans)


t = int(input())

def findPairs(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] < x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result

def findPairs2(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] > x:
			result += r - l
			r -= 1
		else:
			l += 1
	return result
for T in range(t):
	list1 = list(map(int, input().split()))
	n = list1[0]
	l = list1[1]
	r = list1[2]
	a = list(map(int, input().split()))
	answer = n * (n - 1) // 2
	a = sorted(a)
	answer = answer - findPairs(a, n, l) - findPairs2(a, n, r)
	print(answer)


def binsearch1(a, n, i):
	ans = -1
	l = i
	h = len(a) - 1
	while h >= l:
		m = l + (h - l) // 2
		if n <= a[m]:
			ans = m
			h = m - 1
		else:
			l = m + 1
	return ans

def binsearch2(a, n, i):
	ans = -1
	l = i
	h = len(a) - 1
	while h >= l:
		m = l + (h - l) // 2
		if a[m] <= n:
			ans = m
			l = m + 1
		else:
			h = m - 1
	return ans
t = int(input())
for i in range(t):
	(n, l, r) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	a.sort()
	count = 0
	for i in range(n - 1):
		if a[i] > r:
			break
		n1 = l - a[i]
		n2 = r - a[i]
		c = binsearch2(a, n2, i + 1)
		d = binsearch1(a, n1, i + 1)
		if c >= 0 and d >= 0:
			count = count + (c - d + 1)
	print(count)


user_input = lambda : map(int, input().split())
(t,) = user_input()
while t:
	t -= 1
	(n, l, r) = user_input()
	arr1 = user_input()
	arr2 = sorted(arr1)
	ansl = 0
	i = 0
	j = n - 1
	while i < j:
		if arr2[i] + arr2[j] < l:
			ansl += j - i
			i += 1
		else:
			j -= 1
	ansr = 0
	i = 0
	j = n - 1
	while i < j:
		if arr2[i] + arr2[j] < r + 1:
			ansr += j - i
			i += 1
		else:
			j -= 1
	print(ansr - ansl)


from bisect import *
a = int(input())
total = 0
from collections import *
for i in range(a):
	(n, l, r) = map(int, input().split())
	total = 0
	z = list(map(int, input().split()))
	al = defaultdict(int)
	for i in range(len(z)):
		al[z[i]] += 1
	z.sort()
	for i in range(len(z)):
		t = bisect_left(z, l - z[i])
		q = bisect_right(z, r - z[i])
		if t == len(z):
			continue
		if q == len(z):
			q -= 1
		if z[q] + z[i] > r:
			q -= 1
		x = 0
		total += max(q - t + 1, 0)
		if l <= z[i] * 2 <= r:
			x -= 1
		total += x
	print(total // 2)


import collections
from math import ceil, gcd, sqrt, log
INF = float('inf')
mod = 1000000007

def solve():
	(n, l, r) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	net1 = 0
	(i, j) = (0, n - 1)
	while i < j:
		if A[i] + A[j] > r:
			j -= 1
		else:
			net1 += j - i
			i += 1
	net2 = 0
	(i, j) = (0, n - 1)
	while i < j:
		if A[i] + A[j] < l:
			i += 1
		else:
			net2 += j - i
			j -= 1
	net = n * (n - 1) // 2
	ans = abs(net - (net1 + net2))
	print(ans)
t = int(input())
while t != 0:
	solve()
	t -= 1


t = int(input())
for task in range(t):
	(n, l, r) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	res = 0
	lBound = n - 1
	rBound = n - 1
	for i in range(n):
		tmp = lBound
		while tmp > -1 and a[tmp] + a[i] >= l:
			tmp -= 1
		lBound = tmp
		tmp = rBound
		while tmp > -1 and a[tmp] + a[i] > r:
			tmp -= 1
		rBound = tmp
		if rBound < 0:
			break
		res += rBound - max(lBound, -1)
		if i > lBound and i <= rBound:
			res -= 1
	print(res // 2)


from collections import defaultdict
linp = lambda : list(map(int, input().split()))
iinp = lambda : int(input())
tinp = lambda : map(int, input().split())
rinp = lambda : range(int(input()))
dct = lambda : defaultdict(lambda : 0)
from collections import Counter
from math import ceil

def cnt(a, mx, l, r):
	c = 0
	while l < r:
		if a[l] + a[r] <= mx:
			c += r - l
			l += 1
		else:
			r -= 1
	return c
for _ in rinp():
	(n, x, y) = tinp()
	ar = linp()
	ar.sort()
	st = set()
	a = cnt(ar, y, 0, n - 1)
	b = cnt(ar, x - 1, 0, n - 1)
	print(a - b)


def main(n, l, r, arr):
	arr.sort()
	count = 0
	(i, l_idx, r_idx) = (0, len(arr) - 1, len(arr) - 1)
	while i < r_idx:
		l_idx = max(i, l_idx)
		while i < l_idx and arr[i] + arr[l_idx] >= l:
			l_idx -= 1
		while l_idx < r_idx and arr[i] + arr[r_idx] > r:
			r_idx -= 1
		count += r_idx - l_idx
		i += 1
	return count
t = int(input().strip())
for _ in range(t):
	(n, l, r) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	print(main(n, l, r, arr))


def pair(n, l, r, arr):
	arr.sort()
	i = 0
	ans1 = 0
	ans2 = 0
	j = n - 1
	while j > i:
		if arr[i] + arr[j] < l:
			i += 1
		else:
			ans1 += j - i
			j -= 1
	i = 0
	j = n - 1
	while j > i:
		if arr[i] + arr[j] <= r:
			i += 1
		else:
			ans2 += j - i
			j -= 1
	return ans1 - ans2
for _ in range(int(input())):
	(n, l, r) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	print(pair(n, l, r, arr))


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
import heapq
from heapq import heappop, heappush
import bisect
from itertools import groupby

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a / gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def Bsl(a, x):
	i = 0
	j = 0
	left = 0
	right = len(a)
	flag = False
	while left < right:
		mi = (left + right) // 2
		if a[mi] <= x:
			left = mi + 1
			i += 1
		else:
			right = mi
			j += 1
	return left

def Bsl(a, x):
	i = 0
	j = 0
	left = 0
	right = len(a)
	flag = False
	while left < right:
		mi = (left + right) // 2
		if a[mi] <= x:
			left = mi + 1
			i += 1
		else:
			right = mi
			j += 1
	return left

def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n / i
	if n > 2:
		num += 1
	return num
t = I()
for _ in range(t):
	(n, l, r) = lint()
	s = lint()
	s.sort()
	ans = 0
	for i in range(n):
		tm = bisect.bisect_left(s, l - s[i])
		pm = bisect.bisect_right(s, r - s[i])
		if tm == n:
			continue
		else:
			if pm >= i:
				pm = i - 1
			else:
				pm -= 1
			if pm < tm or tm >= i:
				continue
			ans += pm - tm + 1
	print(ans)


from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 0
	for i in range(n):
		left = l - arr[i]
		right = r - arr[i]
		p = bisect_left(arr, left, i + 1)
		q = bisect_right(arr, right, i + 1)
		ans += q - p
	print(ans)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l1.sort()
	i = 0
	cnt = 0
	low = n - 1
	high = n - 1
	while i < high:
		low = max(i, low)
		while low > i and l1[i] + l1[low] >= a:
			low -= 1
		while high > low and l1[i] + l1[high] > b:
			high -= 1
		cnt += high - low
		i += 1
	print(cnt)


t = int(input())
for _ in range(t):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	(c, d) = (0, n - 1)
	(k, m) = (0, 0)
	a.sort()
	while c < d:
		if a[c] + a[d] < l:
			k = k + d - c
			c = c + 1
		else:
			d = d - 1
	(c, d) = (0, n - 1)
	while c < d:
		if a[c] + a[d] > r:
			m = m + d - c
			d = d - 1
		else:
			c = c + 1
	ans = n * (n - 1)
	ans = ans // 2
	ans = ans - k - m
	print(ans)


import bisect as bs

def solve(nums, mx):
	n = len(nums)
	nums = sorted(nums)
	count = 0
	i = 0
	j = n - 1
	while i < j:
		while i < j and nums[i] + nums[j] > mx:
			j -= 1
		count += j - i
		i += 1
	return count

def main():
	t = int(input())
	for _ in range(t):
		(n, l, r) = list(map(int, input().split()))
		nums = list(map(int, input().split()))
		print(solve(nums, r) - solve(nums, l - 1))
main()


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 998244353

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
import heapq, string
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()

	def binaryLesser(x, l):
		r = n - 1
		index = 1e+19
		while l <= r:
			mid = (l + r) // 2
			if arr[mid] >= x:
				index = min(index, mid)
				r = mid - 1
			else:
				l = mid + 1
		return index

	def binaryGreater(x, l):
		r = n - 1
		index = -1
		while l <= r:
			mid = (l + r) // 2
			if arr[mid] <= x:
				index = max(index, mid)
				l = mid + 1
			else:
				r = mid - 1
		return index
	cnt = 0
	for i in range(n - 1):
		left = binaryLesser(l - arr[i], i + 1)
		right = binaryGreater(r - arr[i], i + 1)
		cnt += max(right - left + 1, 0)
	print(cnt)


def lol(arr, t):
	count = 0
	n = len(arr)
	l = 0
	r = len(arr) - 1
	while l < r:
		if arr[l] + arr[r] > t:
			count += r - l
			r -= 1
		else:
			l += 1
	return n * (n - 1) / 2 - count
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	a = lol(arr, r)
	b = lol(arr, l - 1)
	print(int(a - b))


from collections import Counter as count
from bisect import bisect_left, bisect
import sys
from itertools import groupby
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	(n, l, r) = list(map(int, input().split()))
	z = list(map(int, input().split()))
	z.sort()
	ans = 0
	for i in range(n):
		if 2 * z[i] >= l and 2 * z[i] <= r:
			ans -= 1
		if z[i] <= r:
			a = max(0, l - z[i])
			t = bisect_left(z, a)
			t2 = bisect(z, r - z[i])
			ans += t2 - t
	print(ans // 2)


from sys import stdin, stdout
case = int(stdin.readline())
for c in range(case):
	(n, l, r) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	arr.sort()
	if n == 1:
		print(0)
		continue
	if arr[-1] + arr[-2] < l:
		print(0)
		continue
	if arr[0] + arr[1] > r:
		print(0)
		continue
	cnt1 = 0
	lp = 0
	rp = n - 1
	while 1:
		if lp >= rp:
			break
		if arr[lp] + arr[rp] > r:
			rp -= 1
		elif rp == n - 1:
			cnt1 += rp - lp
			lp += 1
		elif arr[lp] + arr[rp + 1] > r:
			cnt1 += rp - lp
			lp += 1
		else:
			rp += 1
	cnt2 = 0
	lp = 0
	rp = n - 1
	while 1:
		if lp >= rp:
			break
		if arr[lp] + arr[rp] >= l:
			rp -= 1
		elif rp == n - 1:
			cnt2 += rp - lp
			lp += 1
		elif arr[lp] + arr[rp + 1] >= l:
			cnt2 += rp - lp
			lp += 1
		else:
			rp += 1
	print(cnt1 - cnt2)


import sys
input = sys.stdin.readline
from bisect import bisect

def solve():
	(n, l, r) = map(int, input().split())
	lis = list(map(int, input().split()))
	lis = sorted(lis)
	count = 0
	for i in range(len(lis)):
		start = bisect(lis, l - lis[i] - 1)
		end = bisect(lis, r - lis[i])
		add = 0
		if i >= start and i < end:
			add = -1
		add += end - start
		count += add
	print(count // 2)
for _ in range(int(input())):
	solve()


def solve(arr, l, r, k, x):
	ans = -1
	while l <= r:
		m = l + (r - l) // 2
		if arr[m] <= k:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def sol(arr, l, r, k, x):
	ans = -1
	while l <= r:
		m = (r + l) // 2
		if arr[m] >= k:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
for u in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	for i in range(n):
		(x, y) = (l - a[i], r - a[i])
		p = sol(a, i + 1, n - 1, x, y)
		q = solve(a, i + 1, n - 1, y, x)
		if p != -1 and q != -1:
			c += q - p + 1
	print(c)


def mini(l, n, i, val):
	ans = -1
	j = n - 1
	k = l[i - 1]
	while i <= j:
		mid = i + (j - i) // 2
		if l[mid] + k >= val:
			ans = mid
			j = mid - 1
		else:
			i = mid + 1
	return ans

def maxi(l, n, i, val):
	ans = -1
	j = n - 1
	k = l[i - 1]
	while i <= j:
		mid = i + (j - i) // 2
		if l[mid] + k <= val:
			ans = mid
			i = mid + 1
		else:
			j = mid - 1
	return ans
t = int(input())
for _ in range(t):
	(n, left, right) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	ans = 0
	for i in range(n):
		x = mini(l, n, i + 1, left)
		y = maxi(l, n, i + 1, right)
		if x == -1 or y == -1 or x > y:
			continue
		ans += y - x + 1
	print(ans)


import sys
import math
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7

def Int():
	return int(input())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def BinarySearchl(s, e, a, x):
	while s <= e:
		mid = (s + e) // 2
		if a[mid] < x:
			s = mid + 1
		else:
			e = mid - 1
	return s

def BinarySearchr(s, e, a, x):
	while s <= e:
		mid = (s + e) // 2
		if a[mid] > x:
			e = mid - 1
		else:
			s = mid + 1
	return e

def Q3():
	for _ in range(Int()):
		(n, l, r) = Mint()
		a = List()
		a.sort()
		ans = 0
		for i in range(n):
			idx1 = BinarySearchl(i + 1, n - 1, a, l - a[i])
			idx2 = BinarySearchr(i + 1, n - 1, a, r - a[i])
			ans += idx2 - idx1 + 1
		print(ans)
Q3()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from sys import stdin
input = stdin.readline

def f(a, l, r):
	a = sorted(a)
	temp = []
	ans = 0
	for ind in range(len(a)):
		i = a[ind]
		lr = bl(a, l - i, lo=ind + 1)
		rr = br(a, r - i, lo=ind + 1)
		ans += rr - lr
	return ans
for i in range(int(input())):
	(a, b, c) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	print(f(lst, b, c))


t = int(input())
for _ in range(t):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	t1 = [0] * n
	t2 = [0] * n
	(i, j) = (0, n - 1)
	while i - j <= 0:
		if a[i] + a[j] >= l:
			t1[j] = i
			j -= 1
		else:
			t1[i] = j + 1
			i += 1
	(i, j) = (0, n - 1)
	while i - j <= 0:
		if a[i] + a[j] <= r:
			t2[i] = j
			i += 1
		else:
			t2[j] = i - 1
			j -= 1
	ans = [x2 - x1 + 1 - (x1 <= i <= x2) for (i, (x1, x2)) in enumerate(zip(t1, t2))]
	print(sum(ans) // 2)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	(i, j) = (0, n - 1)
	c = 0
	while i < j:
		if a[i] + a[j] <= r:
			c += j - i
			i += 1
		else:
			j -= 1
	(i, j) = (0, n - 1)
	while i < j:
		if a[i] + a[j] < l:
			c -= j - i
			i += 1
		else:
			j -= 1
	print(c)


def fun(l, k):
	count = 0
	n = len(l)
	i = 0
	j = n - 1
	while i < j:
		if l[i] + l[j] < k:
			count += j - i
			i += 1
		else:
			j -= 1
	return count
t = int(input())
for t in range(t):
	(n, l, r) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	d1 = fun(li, r + 1)
	d2 = fun(li, l)
	print(d1 - d2)


def paris(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] <= x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
t = int(input())
for i in range(t):
	info = list(map(int, input().split()))
	n = info[0]
	l = info[1]
	r = info[2]
	arr = list(map(int, input().split()))
	arr.sort()
	print(paris(arr, n, r) - paris(arr, n, l - 1))


import bisect
t = int(input())
for _ in range(t):
	(n, l, r) = [int(i) for i in input().split()]
	a = sorted([int(i) for i in input().split()])
	ls = rs = 0
	for i in range(len(a)):
		lm1 = bisect.bisect_right(a, l - 1 - a[i])
		ls += max(0, lm1 - i - 1)
		ler = bisect.bisect_right(a, r - a[i])
		rs += max(0, ler - i - 1)
	print(rs - ls)


from math import ceil
t = int(input())
for _ in [0] * t:
	(n, l, r) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	m = -1
	for index in range(len(a)):
		m = index
		if a[index] >= r:
			break
	ans = 0
	for index in range(len(a) - 1):
		(ind1, ind2) = (-1, -1)
		if a[index] < r:
			lower = index + 1
			upper = m
			mid = 0
			while lower < upper - 1:
				mid = (lower + upper) // 2
				if a[index] + a[mid] > r:
					upper = mid
				else:
					lower = mid
			if a[upper] + a[index] <= r and a[upper] + a[index] >= l:
				ind1 = upper
			elif a[lower] + a[index] <= r and a[lower] + a[index] >= l:
				ind1 = lower
			lower = index + 1
			upper = m
			mid = 0
			while lower < upper - 1:
				mid = (lower + upper) // 2
				if a[index] + a[mid] < l:
					lower = mid
				else:
					upper = mid
			if a[lower] + a[index] >= l:
				ind2 = lower
			else:
				ind2 = upper
			if ind1 == -1:
				continue
			else:
				ans += ind1 - ind2 + 1
	print(ans)


def pair(a, x):
	p = 0
	(l, r) = (0, len(a) - 1)
	while l < r:
		if a[l] + a[r] <= x:
			p += r - l
		else:
			while a[l] + a[r] > x and r > l:
				r -= 1
			if r > l:
				p += r - l
		l += 1
	return p
for _ in range(int(input())):
	(n, l, r) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	print(pair(a, r) - pair(a, l - 1))


from collections import defaultdict
t = int(input())
for i in range(0, t):
	(n, left, right) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	ans = n * (n - 1) // 2
	i = 0
	j = n - 1
	c = 0
	while i < j:
		if l[j] + l[i] < left:
			c += j - i
			i += 1
		else:
			j -= 1
	i = 0
	j = n - 1
	x = 0
	while i < j:
		if l[j] + l[i] <= right:
			x += j - i
			i += 1
		else:
			j -= 1
	d = n * (n - 1) // 2 - x
	ans -= c
	ans -= d
	print(ans)


import math

def sol(A, l, r):
	A = sorted(A)
	(greater_than_r, less_than_l) = (0, 0)
	(i, j) = (0, len(A) - 1)
	while i < j:
		if A[i] + A[j] > r:
			greater_than_r += j - i
			j -= 1
		else:
			i += 1
	(i, j) = (0, len(A) - 1)
	while i < j:
		if A[i] + A[j] < l:
			less_than_l += j - i
			i += 1
		else:
			j -= 1
	return math.comb(len(A), 2) - greater_than_r - less_than_l
x = int(input())
for _ in range(x):
	y = list(map(int, input().split()))
	A = list(map(int, input().split()))
	print(sol(A, y[1], y[2]))


def solve():
	(n, l, r) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	(start, end) = (0, n - 1)
	res = 0
	for i in range(n):
		(l_bin, r_bin) = (i, n)
		while r_bin - l_bin > 1:
			mid = (r_bin + l_bin) // 2
			if a[i] + a[mid] < l:
				l_bin = mid
			elif a[i] + a[mid] >= l:
				r_bin = mid
		l_bound = r_bin
		(l_bin, r_bin) = (i, n)
		while r_bin - l_bin > 1:
			mid = (r_bin + l_bin) // 2
			if a[i] + a[mid] <= r:
				l_bin = mid
			elif a[i] + a[mid] > r:
				r_bin = mid
		r_bound = r_bin
		res += r_bound - l_bound
	print(res)
for t in range(int(input())):
	solve()


from bisect import bisect_left, bisect_right
for __ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	ans = 0
	for i in range(n):
		mi = bisect_left(a, l - a[i])
		ma = bisect_right(a, r - a[i])
		if ma == n or a[ma] > r - a[i]:
			ma -= 1
		ans += ma - mi + 1
		if l <= a[i] + a[i] <= r:
			ans -= 1
	print(ans // 2)


def count_below(cutoff):
	ans = 0
	big = n - 1
	for small in range(n):
		while big > small and a[small] + a[big] > cutoff:
			big -= 1
		ans += max(0, big - small)
	return ans
t = int(input())
for _ in range(t):
	(n, l, r) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	ans = count_below(r)
	ans -= count_below(l - 1)
	print(ans)


import os
import sys
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def scanf(datatype=str):
	return datatype(sys.stdin.readline().rstrip())

def printf(answer=''):
	return sys.stdout.write(str(answer) + '\n')

def prints(answer):
	return sys.stdout.write(str(answer) + ' ')

def map_input(datatype=str):
	return map(datatype, sys.stdin.readline().split())

def list_input(datatype=str):
	return list(map(datatype, sys.stdin.readline().split()))

def testcase(number: int, solve_function):
	for i in range(number):
		printf(solve_function())

def solve():
	(n, l, r) = map_input(int)
	count = 0
	arr = list_input(int)
	arr.sort()
	for i in range(n):
		low = bisect_left(arr, l - arr[i], i + 1, n)
		high = bisect_right(arr, r - arr[i], i + 1, n)
		count += high - low
	return count
t = scanf(int)
testcase(t, solve)


def d_c_check(arr, max_val):
	size = len(arr)
	i = 0
	j = size - 1
	res = 0
	while i < j:
		if arr[i] + arr[j] > max_val:
			res += j - i
			j -= 1
		else:
			i += 1
	return res
t = int(input())
for z in range(t):
	a = []
	res = 0
	(n, l, r) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort()
	hi_c = d_c_check(a, r)
	low_c = d_c_check(a, l - 1)
	print(low_c - hi_c)


def BSCeil(a, low, high, key):
	mid = (low + high) // 2
	ans = -1
	while low <= high:
		mid = (low + high) // 2
		if a[mid] >= key:
			ans = mid
			high = mid - 1
		else:
			low = mid + 1
	return ans

def BSFloor(a, low, high, key):
	mid = (low + high) // 2
	ans = -1
	while low <= high:
		mid = (low + high) // 2
		if a[mid] <= key:
			ans = mid
			low = mid + 1
		else:
			high = mid - 1
	return ans
for tc in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	for i in range(len(a)):
		x = BSFloor(a, i + 1, len(a) - 1, r - a[i])
		y = BSCeil(a, i + 1, len(a) - 1, l - a[i])
		if x == -1 or y == -1:
			continue
		c += x - y + 1
	print(c)


t = int(input())
for u in range(t):
	l1 = list(map(int, input().rstrip().split()))
	n = l1[0]
	l = l1[1]
	r = l1[2]
	a = list(map(int, input().rstrip().split()))
	a.sort()
	count = 0
	start = 0
	end = n - 1
	while start < end:
		if a[start] + a[end] <= r:
			count += end - start
			start += 1
		else:
			end -= 1
	start = 0
	end = n - 1
	while start < end:
		if a[start] + a[end] < l:
			count -= end - start
			start += 1
		else:
			end -= 1
	print(count)


from bisect import bisect_right

def solve(v, x):
	pcnt = 0
	for (i, e) in enumerate(v):
		j = bisect_right(v, x - e)
		if i < j:
			pcnt += j - i - 1
	return pcnt
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	v = list(map(int, input().split()))
	v = sorted(v)
	print(solve(v, r) - solve(v, l - 1))


import bisect

def solve(arr, n, l, r):
	totalCount = 0
	for i in range(0, n - 1):
		start = l - arr[i]
		end = r - arr[i]
		c1 = bisect.bisect(arr, start - 1, i + 1, n)
		c2 = bisect.bisect(arr, end, i + 1, n)
		totalCount += c2 - c1
	return totalCount
testcases = int(input())
while testcases:
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	tc = solve(arr, n, l, r)
	print(tc)
	testcases -= 1


t = int(input())
while t:
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	cl = n - 1
	cr = n - 1
	ans = 0
	for (i, x) in enumerate(a):
		if i == 0:
			continue
		while cl >= 0 and a[cl] + x >= l:
			cl -= 1
		while cr >= 0 and a[cr] + x > r:
			cr -= 1
		if cr >= cl and cl <= i:
			ans += cr - cl if cr < i else max(i - cl - 1, 0)
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	(i, j, q) = (0, 0, 0)
	while n:
		n -= 1
		while i < n and a[i] + a[n] < l:
			i += 1
		while j < n and a[j] + a[n] <= r:
			j += 1
		q += min(j, n) - min(i, n)
	print(q)


def func(x, n, m):
	l = 0
	r = n - 1
	ans = 0
	while l < r:
		if x[l] + x[r] <= m:
			ans += r - l
			l += 1
		else:
			r -= 1
	return ans
for u in range(int(input())):
	(n, l, r) = map(int, input().split())
	x = [int(w) for w in input().split()]
	x = sorted(x)
	a = func(x, n, r)
	b = func(x, n, l - 1)
	ans = a - b
	print(ans)


import bisect
for _ in range(int(input())):
	(n, l, r) = (int(x) for x in input().split(' '))
	arr = [int(x) for x in input().split(' ')]
	arr = sorted(arr)
	count = 0
	for i in range(n):
		upper = bisect.bisect_right(arr, r - arr[i], i + 1, n)
		lower = bisect.bisect_left(arr, l - arr[i], i + 1, n)
		count += upper - lower
	print(count)


t = int(input())

def count(arr, target):
	s = 0
	(l, r) = (0, len(arr) - 1)
	while l < r and l > -1 and (r < len(arr)):
		if arr[l] + arr[r] <= target:
			s += r - l
			l += 1
		else:
			r -= 1
	return s
for _ in range(t):
	s = input().split()
	(n, l, r) = (int(s[0]), int(s[1]), int(s[2]))
	nums = [int(st) for st in input().split()]
	nums.sort()
	print(count(nums, r) - count(nums, l - 1))


import math

def main():

	def solve(N, L, R, H):
		H.sort()
		return helper(H, R) - helper(H, L - 1)

	def helper(H, lim):
		(i, j) = (0, len(H) - 1)
		count = 0
		while i < j:
			if H[i] + H[j] <= lim:
				count += j - i
				i += 1
			else:
				j -= 1
		return count

	def read_input():
		number_tests = int(input())
		for i in range(number_tests):
			(N, L, R) = input().split()
			H = input().split()
			H = list(map(lambda x: int(x), H))
			print(solve(int(N), int(L), int(R), H))
	read_input()
main()


for _ in range(int(input())):
	(n, s, r) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	l = sorted(l)
	i = 0
	h = n - 1
	b = n - 1
	while i < h:
		b = max(i, b)
		while b > i and l[i] + l[b] >= s:
			b -= 1
		while h > b and l[i] + l[h] > r:
			h -= 1
		c += h - b
		i += 1
	print(c)


def func(a, n):
	count = 0
	i = 0
	j = len(a) - 1
	while i < j:
		if a[i] + a[j] >= n:
			j -= 1
		else:
			count += j - i
			i += 1
	return count
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	d1 = func(a, l)
	d2 = func(a, r + 1)
	print(d2 - d1)


t = int(input())
for T in range(t):
	(n, l, r) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort()
	(count, i, ind) = (0, 0, 0)
	while i < n:
		n -= 1
		while i < n and a[i] + a[n] < l:
			i += 1
		while ind < n and a[ind] + a[n] <= r:
			ind += 1
		count += min(n, ind) - i
	print(count)


from collections import defaultdict
from bisect import bisect_right, bisect_left, insort
import heapq

def main():
	for _ in range(int(input())):
		(n, l, r) = list(map(int, input().split()))
		d = defaultdict(int)
		a = list(map(int, input().split()))
		k = SortedList(a)
		ans = 0
		for i in range(n - 1):
			k.discard(a[i])
			z = bisect_right(k, r - a[i]) - 1
			if z == -1:
				continue
			if a[i] > l:
				p = 0
			else:
				p = bisect_left(k, l - a[i])
			if p == len(k) or a[i] >= r:
				continue
			ans += z - p + 1
		print(ans)
div = [0] * 1000001

def NumOfDivisors(n):
	for i in range(1, n + 1):
		for j in range(i, n + 1, i):
			div[j] += 1

def primes1(n):
	sieve = [True] * (n // 2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i // 2]:
			sieve[i * i // 2::i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [2 * i + 1 for i in range(1, n // 2) if sieve[i]]

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

class Graph:

	def __init__(self):
		self.Graph = defaultdict(list)

	def addEdge(self, u, v):
		self.Graph[u].append(v)
		self.Graph[v].append(u)

	def DFSUtil(self, v, visited):
		visited.add(v)
		for neighbour in self.Graph[v]:
			if neighbour not in visited:
				self.DFSUtil(neighbour, visited)

	def DFS(self, v):
		visited = set()
		self.DFSUtil(v, visited)

	def BFS(self, s):
		visited = set()
		queue = []
		queue.append(s)
		visited.add(s)
		while queue:
			s = queue.pop(0)
			for i in self.Graph[s]:
				if i not in visited:
					queue.append(i)
					visited.add(i)

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
main()


def co(a, n):
	i = 0
	j = len(a) - 1
	c = 0
	while i < j:
		if a[i] + a[j] < n:
			c += j - i
			i += 1
		else:
			j -= 1
	return c
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	x = co(a, l)
	y = co(a, r + 1)
	print(y - x)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	ans = 0
	x = [0] * n
	y = [0] * n
	(i, j) = (0, n - 1)
	while i - j <= 0:
		if a[i] + a[j] >= l:
			x[j] = i
			j -= 1
		else:
			x[i] = j + 1
			i += 1
	(i, j) = (0, n - 1)
	while i - j <= 0:
		if a[i] + a[j] <= r:
			y[i] = j
			i += 1
		else:
			y[j] = i - 1
			j -= 1
	ans = [o2 - o + 1 - (o <= i <= o2) for (i, (o, o2)) in enumerate(zip(x, y))]
	print(int(sum(ans) / 2))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def solve():
	(n, l, r) = takeivr()
	arr = takeiar()
	arr.sort()
	count = 0
	for i in range(n):
		if arr[i] >= r:
			break
		count -= bisect_left(arr, l - arr[i], 0, n)
		count += bisect_right(arr, r - arr[i], 0, n)
		if 2 * arr[i] >= l and 2 * arr[i] <= r:
			count -= 1
	print(count // 2)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = takein()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
from bisect import bisect_left, bisect_right
for _ in range(rn()):
	(n, l, r) = rns()
	a = rl()
	a.sort()
	ans = 0
	for num in a:
		left = bisect_left(a, l - num)
		right = bisect_right(a, r - num)
		if (left < n and num >= a[left]) and (0 < right <= n and num <= a[right - 1]):
			ans -= 1
		ans += right - left
	print(ans // 2)


import sys
import math
import collections
import heapq
input = sys.stdin.readline
t = int(input())
for w in range(t):
	(n, l, r) = (int(i) for i in input().split())
	l1 = sorted([int(i) for i in input().split()])
	i = 0
	j = n - 1
	c = 0
	while i < j:
		if l1[i] + l1[j] >= l:
			j -= 1
		else:
			c += j - i
			i += 1
	i = 0
	j = n - 1
	while i < j:
		if l1[i] + l1[j] <= r:
			i += 1
		else:
			c += j - i
			j -= 1
	print(n * (n - 1) // 2 - c)


from sys import stdin
T = stdin.readline()
T = int(T)

def mergeSort(arr, N):
	temp_arr = [0] * N
	return _merge(arr, temp_arr, 0, N - 1)

def _merge(arr, temp_arr, left, right):
	inv_c = 0
	if left > right:
		return inv_c
	if left < right:
		m = (left + right) // 2
		inv_c = inv_c + _merge(arr, temp_arr, left, m)
		inv_c = inv_c + _merge(arr, temp_arr, m + 1, right)
		inv_c = inv_c + merge(arr, temp_arr, left, m, right)
	return inv_c

def merge(arr, temp_arr, left, mid, right):
	global r
	global l
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	for ia in range(i, mid + 1, 1):
		p1 = j
		p2 = right
		a1 = -1
		a2 = -1
		while p1 <= p2:
			m = (p1 + p2) // 2
			if arr[ia] + arr[m] < l:
				p1 = m + 1
			else:
				a1 = m
				p2 = m - 1
		p2 = right
		p1 = j
		while p1 <= p2:
			m = (p1 + p2) // 2
			if arr[m] + arr[ia] > r:
				p2 = m - 1
			else:
				a2 = m
				p1 = m + 1
		if a2 != -1 and a1 != -1:
			if a2 - a1 >= -1 + 1:
				inv_count += a2 - a1 + 1
	while j <= right and i <= mid:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for zz in range(left, right + 1, 1):
		arr[zz] = temp_arr[zz]
	return inv_count
for z in range(0, T, 1):
	global r
	global l
	(N, l, r) = stdin.readline().split()
	N = int(N)
	l = int(l)
	r = int(r)
	L = input().split()
	for i in range(N):
		L[i] = int(L[i])
	print(mergeSort(L, N))


from bisect import bisect_left, bisect_right
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	for i in range(n):
		if a[i] >= r:
			break
		lowlim = bisect_left(a, l - a[i], i + 1)
		highlim = bisect_right(a, r - a[i], i + 1)
		ans += highlim - lowlim
	print(ans)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	nums = list(map(int, input().split()))
	nums.sort()
	(low, high) = (n - 1, n - 1)
	i = 0
	count = 0
	while i < high:
		low = max(i, low)
		while low > i and nums[i] + nums[low] >= l:
			low -= 1
		while high > low and nums[i] + nums[high] > r:
			high -= 1
		count += high - low
		i += 1
	print(count)


import sys

def till_some_range(a, n, till_range):
	start = 0
	end = n - 1
	valid_pairs = 0
	while start < end:
		if a[start] + a[end] < till_range:
			valid_pairs += end - start
			start += 1
		else:
			end -= 1
	return valid_pairs

def solve(a, n, l, r):
	pairs = 0
	a.sort()
	pairs += till_some_range(a, n, r + 1)
	pairs -= till_some_range(a, n, l)
	return pairs
i = sys.stdin.readline
for _ in range(int(i())):
	(n, l, r) = tuple(map(int, i().split()))
	a = list(map(int, i().split()))
	result = solve(a, n, l, r)
	print(result)


def findPairs(arr, n, x):
	l = 0
	r = n - 1
	result = 0
	while l < r:
		if arr[l] + arr[r] < x:
			result += r - l
			l += 1
		else:
			r -= 1
	return result
for i in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr.sort()
	print(findPairs(arr, n, r + 1) - findPairs(arr, n, l))


t = int(input())
for i in range(t):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	a = 0
	b = n - 1
	ans1 = 0
	while a < b:
		if arr[a] + arr[b] <= r:
			ans1 += b - a
			a += 1
		else:
			b -= 1
	a = 0
	b = n - 1
	ans2 = 0
	while a < b:
		if arr[a] + arr[b] <= l - 1:
			ans2 += b - a
			a += 1
		else:
			b -= 1
	print(ans1 - ans2)


import sys
input = sys.stdin.readline

def lower_bound(A, Value):
	Left = 0
	Right = len(A) - 1
	while Left != Right:
		Middle = (Left + Right) // 2
		if A[Middle] >= Value:
			Right = Middle
		else:
			Left = Middle + 1
	if A[Left] < Value:
		return len(A)
	return Left

def upper_bound(A, Value):
	Left = 0
	Right = len(A) - 1
	while Left != Right:
		Middle = (Left + Right) // 2
		if A[Middle] > Value:
			Right = Middle
		else:
			Left = Middle + 1
	if A[Left] <= Value:
		return len(A)
	return Left

def main():
	(N, L, R) = map(int, input().split())
	A = sorted(list(map(int, input().split())))
	Ans = 0
	for i in range(N):
		Ans += upper_bound(A, R - A[i]) - lower_bound(A, L - A[i])
		if L - A[i] <= A[i] and A[i] <= R - A[i]:
			Ans -= 1
	print(Ans // 2)
T = int(input())
for _ in range(T):
	main()


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor
cases = int(input())
for _ in range(cases):
	(n, l, r) = map(int, input().split())
	arr = sorted(map(int, input().split()))
	a1 = [0] * n
	a2 = [0] * n
	(i, j) = (0, n - 1)
	while i - j <= 0:
		if arr[i] + arr[j] >= l:
			a1[j] = i
			j -= 1
		else:
			a1[i] = j + 1
			i += 1
	(i, j) = (0, n - 1)
	while i - j <= 0:
		if arr[i] + arr[j] <= r:
			a2[i] = j
			i += 1
		else:
			a2[j] = i - 1
			j -= 1
	ans = [ans2 - ans1 + 1 - (ans1 <= i <= ans2) for (i, (ans1, ans2)) in enumerate(zip(a1, a2))]
	print(sum(ans) // 2)


def find(a, k):
	count = 0
	n = len(a)
	(i, j) = (0, n - 1)
	while i < j:
		if a[i] + a[j] < k:
			count += j - i
			i += 1
		else:
			j -= 1
	return count
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort()
	v1 = find(a, r + 1)
	v2 = find(a, l)
	print(v1 - v2)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	re = 0
	for j in range(a - 1):
		if l[j] + l[j + 1] > c:
			break
		(lo, hi) = (j + 1, a - 1)
		(r1, r2) = (j + 1, a - 1)
		while lo <= hi:
			m = (lo + hi) // 2
			if l[m] == b - l[j]:
				r1 = m
				hi = m - 1
			elif l[m] < b - l[j]:
				r1 = m
				lo = m + 1
			else:
				hi = m - 1
		(lo, hi) = (j + 1, a - 1)
		while lo <= hi:
			m = (lo + hi) // 2
			if l[m] == c - l[j]:
				r2 = m
				lo = m + 1
			elif l[m] > c - l[j]:
				r2 = m
				hi = m - 1
			else:
				lo = m + 1
		if l[j] + l[r1] < b:
			r1 += 1
		if l[j] + l[r2] > c:
			r2 -= 1
		if r1 < a and r2 >= 0 and (r2 != j) and (l[r1] + l[j] >= b and l[r1] + l[j] <= c) and (l[r2] + l[j] >= b and l[r2] + l[j] <= c):
			re += r2 - r1 + 1
	print(re)


from bisect import bisect_left as bl
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	countl = countr = 0
	for i in range(n):
		x = l - arr[i]
		j = bl(arr, x)
		countl += j
		x = r + 1 - arr[i]
		j = bl(arr, x)
		countr += j
		countr -= 1 if l <= 2 * arr[i] <= r else 0
	print((countr - countl) // 2)


import sys
lines = sys.stdin.read().strip().split('\n')
t = int(lines[0])
for _ in range(t):
	(n, l, r) = map(int, lines[_ * 2 + 1].strip().split())
	nums = list(map(int, lines[_ * 2 + 2].strip().split()))
	nums.sort()
	start = -1
	for (i, target) in enumerate(nums):
		if target + nums[-1] >= l:
			start = i
			break
	if start == -1:
		print(0)
		continue
	(i, left, right) = (start, n - 1, n - 1)
	count = 0
	while i < right:
		target = nums[i]
		while left > i and target + nums[left] >= l:
			left -= 1
		if i > left:
			count += (1 + right - i) * (right - i) // 2
			break
		left += 1
		while right >= left and target + nums[right] > r:
			right -= 1
		if left > right:
			i += 1
			continue
		count += right - left + 1
		i += 1
	print(count)


for _ in [0] * int(input()):
	(n, l, r) = map(int, input().split())
	a = sorted(map(int, input().split()))
	t = 0
	(start, end) = (0, n - 1)
	while start < end:
		if a[start] + a[end] > r:
			t += end - start
			end -= 1
		else:
			start += 1
	(start, end) = (0, n - 1)
	while start < end:
		if a[start] + a[end] < l:
			t += end - start
			start += 1
		else:
			end -= 1
	print(n * (n - 1) // 2 - t)


for i in range(int(input())):
	(n, l, r) = map(int, input().split())
	lst = sorted(list(map(int, input().split())))
	i = 0
	j = 0
	ret = 0
	while i < n:
		n -= 1
		while i < n and lst[i] + lst[n] < l:
			i += 1
		while j < n and lst[j] + lst[n] <= r:
			j += 1
		ret += min(j, n) - i
	print(ret)


for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	s = sorted(map(int, input().split()))
	(lo, h) = (0, n - 1)
	ans = 0
	while lo < h:
		s1 = s[lo] + s[h]
		if s1 < l:
			ans += h - lo
			lo += 1
		else:
			h -= 1
	(lo, h) = (0, n - 1)
	while lo < h:
		s1 = s[lo] + s[h]
		if s1 > r:
			ans += h - lo
			h -= 1
		else:
			lo += 1
	total = n * (n - 1) // 2
	print(total - ans)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def helper(arr, summ):
	n = len(arr)
	i = 0
	j = n - 1
	ans = 0
	while i < j:
		x = arr[i] + arr[j]
		if x <= summ:
			ans += j - i
			i += 1
		else:
			j -= 1
	return ans

def solve():
	for _ in range(get_int()):
		(n, l, r) = get_ints()
		arr = get_list()
		arr.sort()
		get_print_int(helper(arr, r) - helper(arr, l - 1))
solve()


import math
import sys
import bisect
from collections import deque
import time
input = sys.stdin.readline
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, a, b) = invr()
	l = inlt()
	l.sort()
	c = 0
	for i in range(n - 1):
		x = bisect.bisect_left(l, a - l[i], lo=i + 1, hi=n)
		y = bisect.bisect_right(l, b - l[i], lo=i + 1, hi=n)
		c += y - x
	print(c)


import bisect
for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	nums = list(map(int, input().split()))
	nums.sort()
	s = 0
	for i in range(n):
		a = x - nums[i]
		b = y - nums[i]
		aind = bisect.bisect_left(nums, a)
		bind = bisect.bisect_right(nums, b)
		if bind <= i:
			break
		elif aind < i:
			s += bind - i - 1
		elif aind == i:
			if nums[aind] == a:
				s += bind - i - 1
			else:
				s += bind - i - 1
		else:
			s += bind - aind
	print(s)


from bisect import *
for _ in range(int(input())):
	(n, l, r) = map(int, input().split())
	li = sorted(map(int, input().split()))
	ans = 0
	for i in range(len(li)):
		primaryl = l - li[i]
		left = bisect_left(li, primaryl, i + 1)
		primaryr = r - li[i]
		right = bisect_right(li, primaryr, i + 1)
		ans += right - left
	print(ans)


T = int(input())
for case in range(T):
	(n, l, r) = list(map(int, input().split()))
	arr = sorted(list(map(int, input().split())))
	c = 0
	i = 0
	h = n - 1
	b = n - 1
	while i < h:
		b = max(i, b)
		while b > i and arr[i] + arr[b] >= l:
			b -= 1
		while h > b and arr[i] + arr[h] > r:
			h -= 1
		c += h - b
		i += 1
	print(c)


from sys import stdin
for __ in range(int(stdin.readline())):
	(n, l, r) = map(int, stdin.readline().split())
	li = [*map(int, stdin.readline().split())]
	li.sort()
	c = 0
	i = 0
	low = n - 1
	high = n - 1
	while i < high:
		low = max(i, low)
		while low > i and li[i] + li[low] >= l:
			low -= 1
		while high > low and li[i] + li[high] > r:
			high -= 1
		c += high - low
		i += 1
	print(c)


import sys
input = sys.stdin.buffer.readline

def im():
	return map(int, input().split())

def ii():
	return int(input())

def il():
	return list(map(int, input().split()))

def ins():
	return input()[:-1]
import math
for _ in range(ii()):
	(n, l, r) = im()
	lis = il()
	lis.sort()
	ans = 0
	for i in range(n - 1):
		lindex = float('inf')
		rindex = float('inf')
		val = l - lis[i]
		left = i + 1
		right = n - 1
		while left < right:
			mid = (left + right) // 2
			if lis[mid] >= val:
				right = mid
			else:
				left = mid + 1
		if lis[left] + lis[i] >= l:
			lindex = left
		val = r - lis[i]
		left = i + 1
		right = n - 1
		while left < right:
			mid = math.ceil((left + right) / 2)
			if lis[mid] <= val:
				left = mid
			else:
				right = mid - 1
		if lis[left] + lis[i] <= r:
			rindex = left
		if lindex != float('inf') and rindex != float('inf') and (lindex <= rindex):
			ans += rindex - lindex + 1
	print(ans)


t = int(input())
for q in range(t):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	res = 0
	j = 0
	i = 0
	while i < n:
		n -= 1
		while i < n and a[i] + a[n] < l:
			i += 1
		while j < n and a[j] + a[n] <= r:
			j += 1
		res += min(j, n) - i
	print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from bisect import bisect_left, bisect_right

class Result:

	def __init__(self, index, value):
		self.index = index
		self.value = value

class BinarySearch:

	def __init__(self):
		pass

	@staticmethod
	def greater_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_right(func, num)
			if index == len(func):
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(omega) <= num:
				return Result(None, None)
			while alpha < omega:
				if func(alpha) > num:
					return Result(alpha, func(alpha))
				if omega == alpha + 1:
					return Result(omega, func(omega))
				mid = (alpha + omega) // 2
				if func(mid) > num:
					omega = mid
				else:
					alpha = mid

	@staticmethod
	def less_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_left(func, num) - 1
			if index == -1:
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(alpha) >= num:
				return Result(None, None)
			while alpha < omega:
				if func(omega) < num:
					return Result(omega, func(omega))
				if omega == alpha + 1:
					return Result(alpha, func(alpha))
				mid = (alpha + omega) // 2
				if func(mid) < num:
					alpha = mid
				else:
					omega = mid
bs = BinarySearch()
for _ in range(int(input()) if True else 1):
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	ans = 0
	for i in range(n):
		x = bs.greater_than(l - a[i] - 1, a).index
		y = bs.less_than(r - a[i] + 1, a).index
		if x is None or y is None:
			continue
		ans += y - x + 1
		if l <= 2 * a[i] <= r:
			ans -= 1
	print(ans // 2)