#include <bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main() {
  long long t;
  cin >> t;
  for (long long o = 0; o < t; o++) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    long long tot = 0, maxi = arr[1], pre = 0, nul = 0;
    for (long long i = 2; i <= n; i++) {
      maxi = max(maxi, arr[i]);
      tot += max(maxi - arr[i] - pre, nul);
      pre = maxi - arr[i];
    }
    cout << tot << '\n';
  }
  return 0;
}
