#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long n;
    cin >> n;
    vector<long long> numbers(n);
    for (long long j = 0; j < n; j++) cin >> numbers[j];
    vector<long long> dp(n);
    dp[0] = 0;
    for (long long j = 1; j < n; j++) {
      if (numbers[j] <= numbers[j - 1])
        dp[j] = dp[j - 1] + numbers[j - 1] - numbers[j];
      else
        dp[j] = dp[j - 1];
    }
    cout << dp[n - 1] << "\n";
  }
}
