#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long *a = new long long[n];
    for (long long i = 0; i < n; i += 1) {
      cin >> a[i];
    }
    long long res = 0;
    for (long long i = 0; i < n - 1; i += 1)
      if (a[i] > a[i + 1]) res += a[i] - a[i + 1];
    cout << res << "\n";
  }
  return 0;
}
