#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int ans = 0;
    for (int i = n - 1; i >= 1; i--) {
      if (a[i] >= a[i - 1]) {
      } else {
        ans += (a[i - 1] - a[i]);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
