#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC target("avx2")
#pragma GCC optimize("O3, bmi, unroll-loops")

using namespace __gnu_pbds;
using namespace std;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

#define int ll
#define ALL(x) x.begin(), x.end()

const int MAXN = 3e5 + 5;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

struct segmentTree
{
    vector<int> t;
    vector<int> lazy;
    int sz = 1;
    void build(int v, int l, int r, vector<int>& a)
    {
        if(r - l == 1)
        {
            t[v] = a[l];
            return;
        }
        int m = (r + l) / 2;
        build(v * 2, l, m, a);
        build(v * 2 + 1, m, r, a);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
    segmentTree(int n, vector<int>& a)
    {
        sz = n;
        t.resize(sz * 4, 0);
        lazy.resize(sz * 4, 0);
        build(1, 0, sz, a);
    }
    void push(int v, int l, int r)
    {
        int m = (l + r) / 2;
        t[v * 2] += lazy[v] * (m - l);
        t[v * 2 + 1] += lazy[v] * (r - m);
        lazy[v * 2] += lazy[v];
        lazy[v * 2 + 1] += lazy[v];
        lazy[v] = 0;
    }
    int get(int v, int l, int r, int L, int R)
    {
        if(r <= L || l >= R)
        {
            return 0;
        }
        if(L <= l && r <= R)
        {
            return t[v];
        }
        push(v, l, r);
        int m = (l + r) / 2;
        return get(v * 2, l, m, L, R) + get(v * 2 + 1, m, r, L, R);
    }
    int get(int l, int r)
    {
        return get(1, 0, sz, l, r);
    }

    void update(int v, int l, int r, int L, int R, int x)
    {
        if(r <= L || l >= R)
        {
            return;
        }
        if(L <= l && r <= R)
        {
            t[v] += x * (r - l);
            lazy[v] += x;
            return;
        }
        push(v, l, r);
        int m = (l + r) / 2;
        update(v * 2, l, m, L, R, x);
        update(v * 2 + 1, m, r, L, R, x);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }

    void update(int l, int r, int x)
    {
        update(1, 0, sz, l, r, x);
    }
};

struct Vec
{
    int x, y;
    Vec()
    {

    }
    Vec(int a, int b)
    {
        x = a;
        y = b;
    }
    int operator %(Vec a)
    {
        return x * a.y - y * a.x;
    }
    int operator *(Vec a)
    {
        return x * a.x + y * a.y;
    }
    Vec operator -(Vec a)
    {
        return {x - a.x, y - a.y};
    }
    Vec operator +(Vec a)
    {
        return {x + a.x, y + a.y};
    }
    Vec operator *(int k)
    {
        return {x * k, y * k};
    }
    int len2(Vec a)
    {
        return (x - a.x) * (x - a.x) + (y - a.y) * (y - a.y);
    }
    ld len(Vec a)
    {
        return sqrtl(len2(a));
    }
};
istream& operator >>(istream& in, Vec& x)
{
    in >> x.x >> x.y;
    return in;
}

ostream& operator <<(ostream& out, Vec& x)
{
    out << x.x << ' ' << x.y;
    return out;
}

struct fenvik
{
    vector<int> fen;
    int sz = 0;
    fenvik(int n)
    {
        sz = n;
        fen.resize(n + 1, 0);
    }

    int get(int pos)
    {
        int ans = 0;
        for (int i = pos; i > 0; i -= i & -i)
        {
            ans += fen[i];
        }
        return ans;
    }

    void change(int pos, int x)
    {
        for (int i = pos; i <= sz; i += i & -i)
        {
            fen[i] += x;
        }
    }
};

int binpow(int base, int exp, int mod = MOD)
{
    if(exp == 0)
    {
        return 1;
    }
    if(exp % 2 == 0)
    {
        auto gg = binpow(base, exp / 2,  mod);
        return gg * gg % mod;
    }
    return base * binpow(base, exp - 1, mod) % mod;
}

vector<int> g[MAXN];

vector<int> s;

int d[MAXN];

void dfs(int x, int deep = 0)
{
    d[x] = deep;
    for (auto i : g[x])
    {
        dfs(i, deep + 1);
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> b;
    int kolvo = 0;
    for(int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        b.push_back(x);
        if(kolvo < n)
        {
            kolvo++;
        }
        else
        {
            kolvo--;
        }
    }
    cout << kolvo * b[0] << '\n';
}

int32_t main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
