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