#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, flag = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-') c = getchar();
  if (c == '-') flag = 0, c = getchar();
  while (c <= '9' && c >= '0') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return flag ? x : -x;
}
const int maxn = 2e5 + 5;
int a[maxn];
int main() {
  int T = read();
  while (T--) {
    int n = read();
    for (int i = (1); i <= (int)(n); i++) a[i] = read();
    long long ans = 0;
    for (int i = (2); i <= (int)(n); i++)
      if (a[i] < a[i - 1]) ans += a[i - 1] - a[i];
    printf("%lld\n", ans);
  }
  return 0;
}
