#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int T;
int n;
int a[N];
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long ans = 0;
  for (int i = n - 1; i >= 1; i--)
    if (a[i] > a[i + 1]) ans += a[i] - a[i + 1];
  printf("%lld\n", ans);
  return;
}
int main() {
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
