#include using namespace std; int main() { int t,n; cin >> t; vectora; bool ok; long long hako,left,right,mokuteki; for(int q=0;q> n; for(int i=0;i> hako; a.emplace_back(hako); } ok=true; for(int i=0;i=a[i+1])ok=false; if(ok){ cout << 0 << endl; continue; } ok=false; hako=a[0]+1e17; for(int i=1;i=a[i]+(i+1)*1e17){ ok=true; break; } hako=a[i]+(i+1)*1e17; } if(ok){ cout << -1 << endl; continue; } left=0; right=1e17; while(left+1!=right){ mokuteki=(left+right)/2; hako=a[0]+mokuteki; ok=true; for(int i=1;i=a[i]+(i+1)*mokuteki){ ok=false; break; } hako=a[i]+(i+1)*mokuteki; } if(ok)right=mokuteki; else left=mokuteki; } cout << right << endl; } return 0; }