#include <bits/stdc++.h>
using namespace std;
long long arr[200300];
void solve() {
  int n;
  long long cnt = 0;
  scanf("%d%lld", &n, &arr[0]);
  for (int i = 1; i < n; i++) {
    scanf("%lld", &arr[i]);
    if (arr[i - 1] > arr[i]) {
      cnt += arr[i - 1] - arr[i];
    }
  }
  printf("%lld\n", cnt);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
