#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
int dx8[8] = {0, 0, 1, -1, -1, -1, 1, 1}, dy8[8] = {1, -1, 0, 0, -1, 1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
const int N = 2e6 + 10;
int a[N];
int cnt, n;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 2; i <= n; i++) {
      if (a[i] >= a[i - 1]) continue;
      cnt += abs(a[i] - a[i - 1]);
    }
    cout << cnt << endl;
  }
  return 0;
}
