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