#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;




int main() {
	/* Enter your code here. Read input from STDIN. Print output to STDOUT */
	int T; cin >> T;
	for (int tc = 0; tc<T; tc++){
		ll N; cin >> N;
        vector<int> eee;
		for(int i=0;i<3;i++){
            int t; cin >> t; eee.push_back(t);
        }
        sort(eee.begin(), eee.end());
        int A = eee[0]; int B = eee[1]; int C = eee[2];
        if(N == 1){
            cout << 0 << "\n";
            continue;
        }
        map<ll, ll> delta; delta[1] = B;
        map<ll, ll> nextnum; nextnum[0] = 1; nextnum[1] = 2;
        
        vector<ll> data; data.push_back(1); data.push_back(1); data.push_back(0);
        ll number = 2;
        vector<ll> cost; cost.push_back(A); cost.push_back(B); cost.push_back(0);
        ll currcost = B;
        
        
        while(true){
            if(number >= N){
                cout << currcost << "\n";
                break;
            }
            ll nextcost = (int)(1e18);
            for(int i=0;i<3;i++){
                nextcost = min(nextcost, data[i] == 0 ? eee[i] : cost[i] + delta[data[i]]);
            }
            for(int i=0;i<3;i++){
                ll pcost = data[i] == 0 ? eee[i] : cost[i] + delta[data[i]];
                if(pcost == nextcost){
                    data[i] = nextnum[data[i]];
                    cost[i] = pcost;
                }
            }
            ll nextnumber = data[0] + data[1] + data[2];
            nextnum[number] = nextnumber;//pretty bad naming...
            delta[number] = nextcost - currcost;
            
            currcost = nextcost;
            number = nextnumber;
        }
	}
	return 0;
}