#include <bits/stdc++.h>
using namespace std;
using namespace std;
void addEdge(vector<int> adj[], int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void DFSUtil(int u, vector<int> adj[], vector<bool> &visited) {
  visited[u] = true;
  for (int i = 0; i < adj[u].size(); i++)
    if (visited[adj[u][i]] == false) {
      DFSUtil(adj[u][i], adj, visited);
    }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    long long int ans = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (a[i] > a[i + 1]) ans += (a[i] - a[i + 1]);
    }
    cout << ans << "\n";
  }
  return 0;
}
