#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

int main(){
  int t;
  cin >> t;
  while(t--) {
    ll l, r;
    cin >> l >> r;
    if(r < 2*l) cout << 0 << endl;
    else cout << (r-2*l+1)*(r-2*l+2)/2 << endl;
  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(b-1)),y(up?b:(a-1)){}_RX(int a):_RX(0,a){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

i64 simulate(vector<int> ops) {

	i64 x = 0;
	i64 y = 0;

	for(auto op : ops) {
		if(op == 1) {
			x += 1;
		} else if(op == 2) {
			y += 1;
		} else if(op == 3) {
			x = x + y;
		} else if(op == 4) {
			y = x + y;
		} else {
			assert(false);
		}
	}

	return x;
}

int main() {

	const i64 N = read_item();

	if(N < 100) {
		printf("%lld\n", N);
		for(auto i : range((int)N)) {
			printf("1\n");
		}
		return 0;
	}

	vector<i64> fib = {0, 1};

	while(true) {

		const int s = fib.size();
		i64 last1 = fib[s - 1];
		i64 last2 = fib[s - 2];

		dbg(last1, last2);

		if(last1 + last2 > N) {
			break;
		}

		i64 p = last1 + last2;
		fib.push_back(p);
		fib.push_back(p + last1);
		assert(p > 0);
		assert(p + last1 > 0);
	}

	const int len = fib.size();
	const int rounds = fib.size() / 2 - 1;
	i64 y = N;

	vector<pair<pair<int, int>, int>> ops;

	for(auto i : range(rounds)) {
		ops.push_back({{i, 0}, 4});
		ops.push_back({{i, 1}, 3});
	}

	for(auto i : revrange(rounds)) {

		i64 p = fib[2 + i * 2];
		i64 q = fib[3 + i * 2];

		if(y >= q) {
			ops.push_back({{rounds - 1 - i - 1, 2}, 1});
			y = y - q;
			dbg(i, q, 1);
		}
		if(y >= p) {
			ops.push_back({{rounds - 1 - i - 1, 2}, 2});
			y = y - p;
			dbg(i, q, 2);
		}
	}

	dbg(y);
	assert(y == 0);

	sort(ops.begin(), ops.end());
	vector<int> ans;

	for(auto& op : ops) {
		// dbg(op.first.first, op.first.second, op.second);
		ans.push_back(op.second);
	}

	i64 true_x = simulate(ans);
	assert(true_x == N);

	printf("%d\n", (int)ans.size());
	for(auto& op : ans) {
		printf("%d\n", op);
	}

	return 0;
}

/* wafdayo~~~ */
