#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(NULL);
  long long t;
  cin >> t;
  for (long long q = 0; q < t; ++q) {
    long long n, k;
    cin >> n;
    vector<long long> a(n);
    long long ans = 0;
    long long d = 0;
    long long ma = 0;
    for (long long i = 0; i < n; ++i) {
      cin >> a[i];
      if (i != 0) {
        if (a[i] < a[i - 1]) {
          ans += a[i - 1] - a[i];
        }
      }
    }
    cout << ans << "\n";
  }
}
