#include using namespace std; void solve() { int n; cin >> n; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } bool cred = true; for (int i = 1; i < n; ++i) { if (a[i - 1] >= a[i]) cred = false; } if (cred) { cout << 0 << "\n"; return; } long long ans = 0; for (int i = 1; i < n; ++i) { if (a[i - 1] < a[i]) continue; ans = max(a[i - 1] - a[i] + 1, ans); } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int test = 1; cin >> test; while (test--) { solve(); } return 0; }