#include <bits/stdc++.h>
using namespace std;
const int mod = 1e8;
const int N = 2e5 + 5;
long long a[N];
long long dp[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] < a[i - 1]) {
        dp[i] = dp[i - 1] + a[i - 1] - a[i];
      } else
        dp[i] = dp[i - 1];
    }
    cout << dp[n - 1] << endl;
  }
  return 0;
}
