#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <numeric>
#include <map>
#include <unordered_map>
#include <cmath>
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define fo(i,n) for (long long i = 0; i < n; i++)
bool comp(pair<char,ll> a, pair<char,ll> b)
{
    return (a.first < b.first);
}
bool comp2(pair<char,ll> a, pair<char,ll> b)
{
    return (a.first > b.first);
}
ll power(ll x, ll y)
{
    ll res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res * x;

        // y must be even now
        y = y >> 1; // y = y/2
        x = x * x; // Change x to x^2
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n,m,i;
    ll a,b;
    string input;
    cin >> i;
    while (i--)
    {
        cin >> n;
        vector<ll> nums(n);
        fo(j,n)
        {
            cin >> nums[j];
        }
        ll count2 = 0;
        ll sum = 0;
        for (int j = 0; j < n; j++)
        {
            if (nums[j] == 1)
            {
            	count2 = 0;
                for (int k = j+1; k < n; k++)
                {
                    if (nums[k] == 2)
                    {
                        count2++;
                    }
                    if (nums[k] == 3)
                    {
                        sum += power(2,count2)-1%998244353;
                    }
                }
            }
        }
        cout << sum << '\n';
    }
}