#include <bits/stdc++.h>

using namespace std;

//#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

#define ff first
#define ss second
#define vt vector
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define ent "\n"
#define sp ' '

using ll  = long long;
using db  = double;
using ldb = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

const ll  INF = 8e18;
const ll  inf = 1e9 + 7;
const int MOD = 998244353;
const int bln = 200;
const int M   = 2e3 + 7;
const int N   = 1e6 + 7;

/*-------------------------main-------------------------*/

ll ans[N];
ll lox[N];

ll dp(ll h, ll w){
    if (h == w) return lox[h] - h * w;
    if (h > w){
        return dp(h - 1, w) + ans[w] + (h - 1) * 1ll * w;
    }
    else {
        return dp(h, w - 1) + ans[h] + (w - 1) * 1ll * h;
    }
}


void solve() {
    #define test
    ll h, w;
    cin >> h >> w;
    cout << dp(h, w) + h * w;
}

void precalc() {
    ans[1] = 1;
    for (int i = 2; i < N; i++){
        ans[i] = ans[i - 1] + i + 1;
    }
    lox[1] = 1;
    ll x = 5;
    for(int i = 2; i < N; ++i) {
        lox[i] = (lox[i - 1]/(i - 1) + x) * 1ll * i;
        x += 2;
    }
}

signed main() {
//  freopen("lca.in", "r", stdin);
//  freopen("lca.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    precalc();
    int testcases;
    #ifdef tests
        cin >> testcases;
    #endif
    #ifdef test
        testcases = 1;
    #endif
    while (testcases--) {
        solve();
    }
    return 0;
}
