//susanoo.fx;

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
 

#include "bits/stdc++.h"
using namespace std;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif


#define SpeedForce          ios_base::sync_with_stdio(0);cin.tie(0);
#define ff                  first
#define ss                  second
#define ll                  long long
#define ull                 unsigned long long
#define pb                  push_back
#define in                  insert
#define vll                 vector<ll>
#define sll                 set<ll>
#define skip                continue
#define dnl                 nl << nl
#define sz(x)               (int)x.size()
#define all(x)              (x).begin(),(x).end()
#define rall(x)             (x).rbegin(),(x).rend()
#define out(v)              for(auto& i : v) cout << i << ' ';


const int N = 1e6 + 12 ;
const long long modd = 1e9 + 7;
const int inf = INT_MAX;
const string alf = "abcdefghijklmnopqrstuvwxyz";
const char nl = '\n' ;
const short dRow[] = {1 , 0 , -1 , 0} ;
const short dCol[] = {0 , 1 , 0 , -1} ;

                                    
void setFO(string s){
    if(s.empty()) return ;
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);    
}


ll dp[N];

void solve(){
    #define test
    int n , m;
    cin >> n >> m;
    // ll mx = max(n , m);
    // if (n < m) swap(n, m);
    dp[1] = 1;
    dp[2] = 2, dp[3] = 5;
    for (ll i = 4; i <= max(n, m); ++ i) {
    	if (i % 2 == 0) {
    		dp[i] = dp[i / 2] * 2 + i;
    	}else  dp[i] = dp[i / 2] + dp[i / 2 + 1] + i;
    	// dbg(dp[i], i);
    }
    ll ans = 0;
    if (min(m , n) != 1)
   		ans = n * m;
    ans += dp[m] * n;
    ans += dp[n] * m;
    cout << ans << nl;
}   


signed main(){
    SpeedForce;
    // setFO("");
    //precalc();
    int T = 1 ;
    int tt = 1;
    #ifdef tests
        cin >> T ;
    #endif
        while(T--){
            // cout << "Case " << tt << ": " << nl;
            solve() ;
            tt ++;
        }
    return 0 ;
}

// ctrl + alt + d for run in cmd