q = int(input())
for i in range(q):
n ,l , r= map(int , input().split())
a = list(map(int , input().split()))
a.sort()
poi1 = 0
poi2 = n-1
ans = 0
while (poi1 < poi2):
if a[poi2]+a[poi1] < r+1:
ans+=(poi2 - poi1)
poi1+=1
else:
poi2-=1
poi3 = 0
poi4 = n-1
ans1 = 0
while (poi3 < poi4):
if a[poi3]+a[poi4] < l:
ans1+=(poi4 - poi3)
poi3+= 1
else:
poi4-=1
print(ans - ans1)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[200005];
void solve() {
int n, l, r;
ll ans = 0;
cin >> n >> l >> r;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n - 1; ++i) {
int l1 = i + 1, r1 = n, mid1 = l1;
while (l1 < r1) {
int mid1 = (l1 + r1) >> 1;
if (l <= a[i] + a[mid1] && a[i] + a[mid1] <= r) {
r1 = mid1;
} else if (a[i] + a[mid1] < l) {
l1 = mid1 + 1;
} else {
r1 = mid1;
}
}
int l2 = i + 1, r2 = n, mid2 = l2;
while (l2 < r2) {
mid2 = (l2 + r2 + 1) >> 1;
if (l <= a[i] + a[mid2] && a[i] + a[mid2] <= r) {
l2 = mid2;
} else if (a[i] + a[mid2] < l) {
l2 = mid2;
} else {
r2 = mid2 - 1;
}
}
if (l <= a[i] + a[l1] && a[i] + a[l1] <= r) ans += (ll)l2 - (ll)l1 + 1;
}
printf("%lld\n", ans);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
516. Longest Palindromic Subsequence | 468. Validate IP Address |
450. Delete Node in a BST | 445. Add Two Numbers II |
442. Find All Duplicates in an Array | 437. Path Sum III |
436. Find Right Interval | 435. Non-overlapping Intervals |
406. Queue Reconstruction by Height | 380. Insert Delete GetRandom O(1) |
332. Reconstruct Itinerary | 368. Largest Divisible Subset |
377. Combination Sum IV | 322. Coin Change |
307. Range Sum Query - Mutable | 287. Find the Duplicate Number |
279. Perfect Squares | 275. H-Index II |
274. H-Index | 260. Single Number III |
240. Search a 2D Matrix II | 238. Product of Array Except Self |
229. Majority Element II | 222. Count Complete Tree Nodes |
215. Kth Largest Element in an Array | 198. House Robber |
153. Find Minimum in Rotated Sorted Array | 150. Evaluate Reverse Polish Notation |
144. Binary Tree Preorder Traversal | 137. Single Number II |