#include<stdio.h>
int main(){
	int t;
  scanf("%d",&t);
  long long l[20000];
  long long r[20000];
  for(int i=0;i<t;i++){
  	scanf("%ld%ld",&l[i],&r[i]);
  }
   for(int i=0;i<t;i++){
     long long ll=l[i];
     long long rr=r[i];
     if(!(rr-ll>=ll&&rr-ll<=rr))printf("0\n");
  	else if(ll!=rr)printf("%ld\n",(rr-ll*2+1)*(rr-ll*2+2)/2);
     else printf("%d\n",ll==0);
  }
}
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi p(n), pl(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
    pl[p[i]] = i;
  }
  vi ans, box(n-1);
  bool flg = false;
  rep(i, n) {
    while(pl[i] != i) {
      int u = p[pl[i]-1];
      swap(p[pl[i]], p[pl[i]-1]);
      if(box[pl[i]-1]) {
        flg = true;
        break;
      }
      box[pl[i]-1] = 1;
      ans.emplace_back(pl[i]-1);
      swap(pl[i], pl[u]);
    }
  }
  if(int(ans.size()) != n-1) flg = true;
  if(flg) cout << "-1\n";
  else {
    rep(i, n-1) {
      cout << ans[i]+1 << '\n';
    }
  }
}