#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long a[200001];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long i = n - 1; i > 0; i--) {
      if (a[i] < a[i - 1]) ans += a[i - 1] - a[i];
    }
    cout << ans << endl;
  }
}
