#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2
#define v(x) (int)(x - 'a')

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int mod = 1e9 + 7;
const int N = 1e5 + 1;
int q, curlen;
int ans[N];
int fac[N];
int inv[N];
int tmp[N];

struct Query {
    int k, n, i;
};

vec <Query> queries;

inline int fpow(int b, int p = mod - 2) {
    ll res = 1;
    ll pow = b;
    for(; p; p >>= 1) {
        if(p & 1) {
            res *= pow;
            res %= mod;
        }
        pow *= pow;
        pow %= mod;
    }
    return res;
}

inline int bin(int a, int b) {
    return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;
}

void input() {
    cin >> q;
    string txt; cin >> txt;
    curlen = len(txt);
    for(int i = 1; i <= q; ++i) {
        int t; cin >> t;
        if(t == 1) {
            string txt; cin >> txt;
            curlen = len(txt);
        } else {
            int k; cin >> k;
            queries.pb({curlen, k, i});
        }
    }
    sort(all(queries), [](Query x, Query y) {
        return x.k < y.k;
    });
}

void calc_fac() {
    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1; i < N; ++i) {
        fac[i] = 1ll * fac[i - 1] * i % mod;
        inv[i] = fpow(fac[i]);
    }
}

void recalc(int k) {
    fill(tmp, tmp + k, 0);
    tmp[k] = 1;
    for(int i = k + 1; i < N; ++i) {
        tmp[i] = (26ll * tmp[i - 1] + 1ll * fpow(25, i - k) * bin(i - 1, k - 1)) % mod;
    }
}

void solve() {
    calc_fac();
    for(int i = 1; i <= q; ++i) {
        ans[i] = -1;
    }
    int curlen = -1;
    for(int i = 0; i < len(queries); ++i) {
        if(curlen != queries[i].k) {
            curlen = queries[i].k;
            recalc(curlen);
        }
        ans[queries[i].i] = tmp[queries[i].n];
    }
    for(int i = 1; i <= q; ++i) {
        if(ans[i] != -1) {
            cout << ans[i] << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2
#define v(x) (int)(x - 'a')

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int mod = 1e9 + 7;
const int N = 1e5 + 1;
int q, curlen;
int ans[N];
int fac[N];
int inv[N];
int tmp[N];

struct Query {
    int k, n, i;
};

vec <Query> queries;

inline int fpow(int b, int p = mod - 2) {
    ll res = 1;
    ll pow = b;
    for(; p; p >>= 1) {
        if(p & 1) {
            res *= pow;
            res %= mod;
        }
        pow *= pow;
        pow %= mod;
    }
    return res;
}

inline int bin(int a, int b) {
    return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;
}

void input() {
    cin >> q;
    string txt; cin >> txt;
    curlen = len(txt);
    for(int i = 1; i <= q; ++i) {
        int t; cin >> t;
        if(t == 1) {
            string txt; cin >> txt;
            curlen = len(txt);
        } else {
            int k; cin >> k;
            queries.pb({curlen, k, i});
        }
    }
    sort(all(queries), [](Query x, Query y) {
        return x.k < y.k;
    });
}

void calc_fac() {
    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1; i < N; ++i) {
        fac[i] = 1ll * fac[i - 1] * i % mod;
        inv[i] = fpow(fac[i]);
    }
}

void recalc(int k) {
    tmp[k] = 1;
    for(int i = k + 1; i < N; ++i) {
        tmp[i] = (26ll * tmp[i - 1] + 1ll * fpow(25, i - k) * bin(i - 1, k - 1)) % mod;
    }
}

void solve() {
    calc_fac();
    for(int i = 1; i <= q; ++i) {
        ans[i] = -1;
    }
    int curlen = -1;
    for(int i = 0; i < len(queries); ++i) {
        if(curlen != queries[i].k) {
            curlen = queries[i].k;
            recalc(curlen);
        }
        ans[queries[i].i] = tmp[queries[i].n];
    }
    for(int i = 1; i <= q; ++i) {
        if(ans[i] != -1) {
            cout << ans[i] << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;
int add(int a, int b) {
	return a + b < mod ? a + b : a + b - mod;
}
int mul(int a, int b) {
	return int(1LL * a * b % mod);
}
int fexp(int b, int e = mod - 2) {
	int ans = 1;
	while(e) {
		if(e & 1) ans = mul(ans, b);
		b = mul(b, b);
		e /= 2;
	}
	return ans;
}

const int N = 100005;
const int B = 333;
int fact[N], ifact[N];
int C(int n, int k) {
	if(k > n) return 0;
	return mul(mul(fact[n], ifact[k]), ifact[n - k]);
}

void solve(int vec[N], int n) {
	for(int len = 0; len < n; len++) vec[len] = 0;
	vec[n] = 1;
	for(int len = n + 1, pt = 25; len < N; len++, pt = mul(pt, 25)) {
		vec[len] = mul(26, vec[len - 1]);
		int tmp = mul(C(len - 1, n - 1), pt);
		vec[len] = add(vec[len], tmp);
	}
}

int prec[B][N];

char str[N];
int n;
int me[N];

int main() {
	fact[0] = 1;
	for(int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
	ifact[N - 1] = fexp(fact[N - 1]);
	for(int i = N - 2; i >= 0; i--) ifact[i] = mul(i + 1, ifact[i + 1]);

	for(int i = 1; i < B; i++) {
		solve(prec[i], i);
	}

	int q;
	scanf("%d", &q);
	scanf(" %s", str);
	n = (int)strlen(str);

	while(q--) {
		int t;
		scanf("%d", &t);
		if(t == 2) {
			int x;
			scanf("%d", &x);
			printf("%d\n", n < B ? prec[n][x] : me[x]);
		}
		else {
			scanf(" %s", str);
			n = (int)strlen(str);
			if(n >= B) {
				solve(me, n);
			}
		}
	}

}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;
int add(int a, int b) {
	return a + b < mod ? a + b : a + b - mod;
}
int mul(int a, int b) {
	return int(1LL * a * b % mod);
}
int fexp(int b, int e = mod - 2) {
	int ans = 1;
	while(e) {
		if(e & 1) ans = mul(ans, b);
		b = mul(b, b);
		e /= 2;
	}
	return ans;
}

const int N = 100005;
const int B = 333;
int fact[N], ifact[N];
int C(int n, int k) {
	if(k > n) return 0;
	return mul(mul(fact[n], ifact[k]), ifact[n - k]);
}

void solve(int vec[N], int n) {
	vec[n] = 1;
	for(int len = n + 1, pt = 25; len < N; len++, pt = mul(pt, 25)) {
		vec[len] = mul(26, vec[len - 1]);
		int tmp = mul(C(len - 1, n - 1), pt);
		vec[len] = add(vec[len], tmp);
	}
}

int prec[B][N];

char str[N];
int n;
int me[N];

int main() {
	fact[0] = 1;
	for(int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
	ifact[N - 1] = fexp(fact[N - 1]);
	for(int i = N - 2; i >= 0; i--) ifact[i] = mul(i + 1, ifact[i + 1]);

	for(int i = 1; i < B; i++) {
		solve(prec[i], i);
	}

	int q;
	scanf("%d", &q);
	scanf(" %s", str);
	n = (int)strlen(str);

	while(q--) {
		int t;
		scanf("%d", &t);
		if(t == 2) {
			int x;
			scanf("%d", &x);
			printf("%d\n", n < B ? prec[n][x] : me[x]);
		}
		else {
			scanf(" %s", str);
			n = (int)strlen(str);
			if(n >= B) {
				solve(me, n);
			}
		}
	}

}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;
int add(int a, int b) {
	return a + b < mod ? a + b : a + b - mod;
}
int mul(int a, int b) {
	return int(1LL * a * b % mod);
}
int fexp(int b, int e = mod - 2) {
	int ans = 1;
	while(e) {
		if(e & 1) ans = mul(ans, b);
		b = mul(b, b);
		e /= 2;
	}
	return ans;
}

const int N = 100005;
const int B = 333;
int fact[N], ifact[N];
int C(int n, int k) {
	if(k > n) return 0;
	return mul(mul(fact[n], ifact[k]), ifact[n - k]);
}

void solve(int vec[N], int n) {
	for(int len = 0; len < n; len++) vec[len] = 0;
	vec[n] = 1;
	for(int len = n + 1, pt = 25; len < N; len++, pt = mul(pt, 25)) {
		vec[len] = mul(26, vec[len - 1]);
		int tmp = mul(C(len - 1, n - 1), pt);
		vec[len] = add(vec[len], tmp);
	}
}

int prec[B][N];

char str[N];
int n;
int me[N];

int main() {
	fact[0] = 1;
	for(int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
	ifact[N - 1] = fexp(fact[N - 1]);
	for(int i = N - 2; i >= 0; i--) ifact[i] = mul(i + 1, ifact[i + 1]);

	for(int i = 1; i < B; i++) {
		solve(prec[i], i);
	}

	int q;
	scanf("%d", &q);
	scanf(" %s", str);
	n = (int)strlen(str);
	if(n >= B) {
		solve(me, n);
	}

	while(q--) {
		int t;
		scanf("%d", &t);
		if(t == 2) {
			int x;
			scanf("%d", &x);
			printf("%d\n", n < B ? prec[n][x] : me[x]);
		}
		else {
			scanf(" %s", str);
			n = (int)strlen(str);
			if(n >= B) {
				solve(me, n);
			}
		}
	}

}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;

int fac[maxn],ifac[maxn],ans[maxn],pw[maxn],pwi[maxn];
vector<pii> v[maxn];

int Pow(int a,int b){
    int ans=1;
    while(b){
	if(b&1) ans=1ll*ans*a %mod;
	a=1ll*a*a %mod;
	b>>=1;
    }
    return ans;
}

inline int C(int n,int k){
    if(n<k) return 0;
    return 1ll*fac[n]*ifac[k] %mod *ifac[n-k] %mod;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);

    fac[0]=ifac[0]=1;
    for(int i=1;i<maxn;i++)
	fac[i]=1ll*i*fac[i-1] %mod;
    ifac[maxn-1]=Pow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	ifac[i]=1ll*(i+1)*ifac[i+1] %mod;
    pw[0]=1;
    for(int i=1;i<maxn;i++)
	pw[i]=25ll*pw[i-1] %mod;
    pwi[maxn-1]=Pow(pw[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	pwi[i]=25ll*pwi[i+1] %mod;

    int q;cin>>q;
    string s;cin>>s;
    int ss=sz(s),c=0;
    while(q--){
	int task;cin>>task;
	if(task==1){
	    cin>>s;
	    ss=sz(s);
	}
	else{
	    int x;cin>>x;
	    v[ss].PB({x,c++});
	}
    }
    for(int ln=1;ln<maxn;ln++){
	sort(v[ln].begin(),v[ln].end());
	int A=pwi[ln],pt=0;
	while(pt<sz(v[ln]) && v[ln][pt].F<ln)
	    ans[v[ln][pt].S]=Pow(26,v[ln][pt].F),pt++;
	for(int i=ln;i<maxn;i++){
	    if(pt==sz(v[ln])) break;
	    while(pt<sz(v[ln]) && v[ln][pt].F==i) ans[v[ln][pt].S]=1ll*A*pw[i] %mod,pt++;
	    A=1ll*(26ll*A+1ll*C(i,ln-1)*pwi[ln-1])%mod *pwi[1] %mod;
	}
    }
    for(int i=0;i<c;i++){
	if(ans[i]<0) ans[i]+=mod;
	cout<<ans[i]<<"\n";
    }
    return 0;
}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;

int fac[maxn],ifac[maxn],ans[maxn],pw[maxn],pwi[maxn];
vector<pii> v[maxn];

int Pow(int a,int b){
    int ans=1;
    while(b){
	if(b&1) ans=1ll*ans*a %mod;
	a=1ll*a*a %mod;
	b>>=1;
    }
    return ans;
}

inline int C(int n,int k){
    if(n<k) return 0;
    return 1ll*fac[n]*ifac[k] %mod *ifac[n-k] %mod;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);

    fac[0]=ifac[0]=1;
    for(int i=1;i<maxn;i++)
	fac[i]=1ll*i*fac[i-1] %mod;
    ifac[maxn-1]=Pow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	ifac[i]=1ll*(i+1)*ifac[i+1] %mod;
    pw[0]=1;
    for(int i=1;i<maxn;i++)
	pw[i]=25ll*pw[i-1] %mod;
    pwi[maxn-1]=Pow(pw[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	pwi[i]=25ll*pwi[i+1] %mod;

    int q;cin>>q;
    string s;cin>>s;
    int ss=sz(s),c=0;
    while(q--){
	int task;cin>>task;
	if(task==1){
	    cin>>s;
	    ss=sz(s);
	}
	else{
	    int x;cin>>x;
	    v[ss].PB({x,c++});
	}
    }
    for(int ln=1;ln<maxn;ln++){
	sort(v[ln].begin(),v[ln].end());
	int A=pwi[ln],pt=0;
	while(pt<sz(v[ln]) && v[ln][pt].F<ln)
	    pt++;
	for(int i=ln;i<maxn;i++){
	    if(pt==sz(v[ln])) break;
	    while(pt<sz(v[ln]) && v[ln][pt].F==i) ans[v[ln][pt].S]=1ll*A*pw[i] %mod,pt++;
	    A=1ll*(26ll*A+1ll*C(i,ln-1)*pwi[ln-1])%mod *pwi[1] %mod;
	}
    }
    for(int i=0;i<c;i++){
	if(ans[i]<0) ans[i]+=mod;
	cout<<ans[i]<<"\n";
    }
    return 0;
}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;

int fac[maxn],ifac[maxn],ans[maxn],pw[maxn],pwi[maxn];
vector<pii> v[maxn];

int Pow(int a,int b){
    int ans=1;
    while(b){
	if(b&1) ans=1ll*ans*a %mod;
	a=1ll*a*a %mod;
	b>>=1;
    }
    return ans;
}

inline int C(int n,int k){
    if(n<k) return 0;
    return 1ll*fac[n]*ifac[k] %mod *ifac[n-k] %mod;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);

    fac[0]=ifac[0]=1;
    for(int i=1;i<maxn;i++)
	fac[i]=1ll*i*fac[i-1] %mod;
    ifac[maxn-1]=Pow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	ifac[i]=1ll*(i+1)*ifac[i+1] %mod;
    pw[0]=1;
    for(int i=1;i<maxn;i++)
	pw[i]=25ll*pw[i-1] %mod;
    pwi[maxn-1]=Pow(pw[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	pwi[i]=25ll*pwi[i+1] %mod;

    int q;cin>>q;
    string s;cin>>s;
    int ss=sz(s),c=0;
    while(q--){
	int task;cin>>task;
	if(task==1){
	    cin>>s;
	    ss=sz(s);
	}
	else{
	    int x;cin>>x;
	    v[ss].PB({x,c++});
	}
    }
    for(int ln=1;ln<maxn;ln++){
	sort(v[ln].begin(),v[ln].end());
	int A=pwi[ln],pt=0;
	while(pt<sz(v[ln]) && v[ln][pt].F<ln)
	    ans[v[ln][pt].S]=Pow(26,v[ln][pt].F),pt++;
	for(int i=ln;i<maxn;i++){
	    if(pt==sz(v[ln])) break;
	    if(v[ln][pt].F==i) ans[v[ln][pt].S]=1ll*A*pw[i] %mod,pt++;
	    A=1ll*(26ll*A+1ll*C(i,ln-1)*pwi[ln-1])%mod *pwi[1] %mod;
	}
    }
    for(int i=0;i<c;i++){
	if(ans[i]<0) ans[i]+=mod;
	cout<<ans[i]<<"\n";
    }
    return 0;
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#include <iomanip>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

int n, m, ans[N], dp[N], fac[N], ifac[N], pw[N], vis[N];
char s[N];
vector<pii> g[N];
int C(int n, int m) {
	return (ll)fac[n]*ifac[m]%P*ifac[n-m]%P;
}
int main() {
	fac[0]=pw[0]=1;
	REP(i,1,N-1) {
		fac[i]=(ll)fac[i-1]*i%P;
		pw[i]=(ll)pw[i-1]*25%P;
	}
	ifac[N-1]=qpow(fac[N-1],P-2);
	PER(i,0,N-2) ifac[i]=(ll)ifac[i+1]*(i+1)%P;
	scanf("%d%s", &m, s+1);
	n = strlen(s+1);
	REP(i,1,m) {
		int op, x;
		scanf("%d", &op);
		if (op==1) scanf("%s",s+1),n=strlen(s+1);
		else {
			vis[i] = 1;
			scanf("%d", &x);
			if (x==n) ans[i] = 1;
			if (x>n) g[n].pb({x,i});
		}
	}
	REP(i,1,N-1) if (g[i].size()) {
		sort(g[i].begin(),g[i].end());
		int mx = g[i].back().x;
		int now = 0, ret = 1;
		REP(x,i+1,mx) {
			ret = (ret*26ll+(ll)pw[x-i]*C(x-1,i-1))%P;
			while (now<g[i].size()&&g[i][now].x==x) {
				ans[g[i][now++].y] = ret;
			}
		}
	}
	REP(i,1,m) if (vis[i]) printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<28;
ll inv[MAX],fac[MAX],finv[MAX];

void make(){

    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;

    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }

}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll perm(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*finv[a-b]%mod;
}

ll rui[27][MAX];

vector<pair<ll,int>> T[MAX];
ll res[MAX];

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int Q;cin>>Q;
    make();
    string S;cin>>S;

    rui[25][0]=rui[26][0]=1;
    for(int i=1;i<MAX;i++){
        rui[25][i]=rui[25][i-1]*25%mod;
        rui[26][i]=rui[26][i-1]*26%mod;
    }
    int now=si(S);
    int id=0;

    while(Q--){
        int t;cin>>t;
        if(t==1){
            cin>>S;
            now=si(S);
        }else{
            ll K;cin>>K;
            K-=now;
            T[now].push_back(mp(K,id));
            id++;
        }
    }

    for(int M=0;M<MAX;M++){
        ll ans=0;
        for(int j=0;j<si(T[M]);j++){
            if(j==0){
                ll K=T[M][j].fi;
                for(int i=0;i<=K;i++){
                    ans+=rui[25][i]*comb(i+M-1,i)%mod*rui[26][K-i]%mod;
                    ans%=mod;
                }
                res[T[M][j].se]=ans;
            }else{
                ans*=rui[26][T[M][j].fi-T[M][j-1].fi];
                ans%=mod;

                ll K=T[M][j].fi;
                for(int i=T[M][j-1].fi+1;i<=K;i++){
                    ans+=rui[25][i]*comb(i+M-1,i)%mod*rui[26][K-i]%mod;
                    ans%=mod;
                }
                res[T[M][j].se]=ans;
            }
        }
    }

    for(int i=0;i<id;i++) cout<<res[i]<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<28;
ll inv[MAX],fac[MAX],finv[MAX];

void make(){

    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;

    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }

}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll perm(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*finv[a-b]%mod;
}

ll rui[27][MAX];

vector<pair<ll,int>> T[MAX];
ll res[MAX];

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int Q;cin>>Q;
    make();
    string S;cin>>S;

    rui[25][0]=rui[26][0]=1;
    for(int i=1;i<MAX;i++){
        rui[25][i]=rui[25][i-1]*25%mod;
        rui[26][i]=rui[26][i-1]*26%mod;
    }
    int now=si(S);
    int id=0;

    while(Q--){
        int t;cin>>t;
        if(t==1){
            cin>>S;
            now=si(S);
        }else{
            ll K;cin>>K;
            K-=now;
            T[now].push_back(mp(K,id));
            id++;
        }
    }

    for(int M=0;M<MAX;M++){
        sort(all(T[M]));
        ll ans=0;
        for(int j=0;j<si(T[M]);j++){
            if(j==0){
                ll K=T[M][j].fi;
                for(int i=0;i<=K;i++){
                    ans+=rui[25][i]*comb(i+M-1,i)%mod*rui[26][K-i]%mod;
                    ans%=mod;
                }
                res[T[M][j].se]=ans;
            }else{
                ans*=rui[26][T[M][j].fi-T[M][j-1].fi];
                ans%=mod;

                ll K=T[M][j].fi;
                for(int i=T[M][j-1].fi+1;i<=K;i++){
                    ans+=rui[25][i]*comb(i+M-1,i)%mod*rui[26][K-i]%mod;
                    ans%=mod;
                }
                res[T[M][j].se]=ans;
            }
        }
    }

    for(int i=0;i<id;i++) cout<<res[i]<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<28;
ll inv[MAX],fac[MAX],finv[MAX];

void make(){

    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;

    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }

}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll perm(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*finv[a-b]%mod;
}

ll rui[MAX][27];

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int Q;cin>>Q;
    make();
    string S;cin>>S;

    rui[0][25]=rui[0][26]=1;
    for(int i=1;i<MAX;i++){
        rui[i][25]=rui[i-1][25]*25%mod;
        rui[i][26]=rui[i-1][26]*26%mod;
    }

    while(Q--){
        int t;cin>>t;
        if(t==1){
            cin>>S;
        }else{
            ll K;cin>>K;
            ll ans=0;
            K-=si(S);

            for(int i=0;i<=K;i++){
                ans+=rui[K-i][25]*comb(K-i+si(S)-1,si(S)-1)%mod*rui[i][26]%mod;
                ans%=mod;
            }

            cout<<ans<<"\n";
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<28;
ll inv[MAX],fac[MAX],finv[MAX];

void make(){

    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;

    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }

}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll perm(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*finv[a-b]%mod;
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int Q;cin>>Q;
    make();
    string S;cin>>S;

    while(Q--){
        int t;cin>>t;
        if(t==1){
            cin>>S;
        }else{
            ll K;cin>>K;
            ll ans=0;
            K-=si(S);

            for(int i=0;i<=K;i++){
                ans+=rui(25,K-i)*comb(K-i+si(S)-1,si(S)-1)%mod*rui(26,i)%mod;
                ans%=mod;
            }

            cout<<ans<<"\n";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return t * t % const1;
	}
	int t = power(a, b / 2);
	t = t * t % const1;
	return t * a % const1;
}
int cnk(int a, int b){
	return fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(1e5) + 3;
    int q = 26;
    vector <vector <int> > dp(t, vector <int> (1e5 + 1));
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = st1[i - 1] * q % const1;
    	st2[i] = st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = dp[0][i - 1] * q % const1;
    	dp[0][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		if(it == dp.size())
    		{
    			cout << "A";
    			return 0;
    		}
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = dp[it][i - 1] * q % const1;
    			dp[it][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return t * t % const1;
	}
	int t = power(a, b / 2);
	t = t * t % const1;
	return t * a % const1;
}
int cnk(int a, int b){
	return fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(1e5) + 10;
    int q = 26;
    vector <vector <int> > dp(t, vector <int> (1e5 + 1));
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = st1[i - 1] * q % const1;
    	st2[i] = st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = dp[0][i - 1] * q % const1;
    	dp[0][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = dp[it][i - 1] * q % const1;
    			dp[it][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return 1LL * t * t % const1;
	}
	int t = power(a, b / 2);
	t = 1LL * t * t % const1;
	return 1LL * t * a % const1;
}
int cnk(int a, int b){
	return 1LL * fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = 1LL * fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = 1LL * fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(2e5) + 3;
    int q = 26;
    int dp[t][100001];
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = 1LL * st1[i - 1] * q % const1;
    	st2[i] = 1LL * st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = 1LL * dp[0][i - 1] * q % const1;
    	dp[0][i] += 1LL * cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = 1LL * dp[it][i - 1] * q % const1;
    			dp[it][i] += 1LL * cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return t * t % const1;
	}
	int t = power(a, b / 2);
	t = t * t % const1;
	return t * a % const1;
}
int cnk(int a, int b){
	return fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(1e5) + 1;
    t *= 2;
    int q = 26;
    vector <vector <int> > dp(t, vector <int> (1e5 + 1));
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = st1[i - 1] * q % const1;
    	st2[i] = st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = dp[0][i - 1] * q % const1;
    	dp[0][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = dp[it][i - 1] * q % const1;
    			dp[it][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return t * t % const1;
	}
	int t = power(a, b / 2);
	t = t * t % const1;
	return t * a % const1;
}
int cnk(int a, int b){
	return fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(1e5) + 1;
    int q = 26;
    vector <vector <int> > dp(t, vector <int> (1e5 + 1));
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = st1[i - 1] * q % const1;
    	st2[i] = st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = dp[0][i - 1] * q % const1;
    	dp[0][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = dp[it][i - 1] * q % const1;
    			dp[it][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return t * t % const1;
	}
	int t = power(a, b / 2);
	t = t * t % const1;
	return t * a % const1;
}
int cnk(int a, int b){
	return fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(1e5) + 10;
    int q = 26;
    vector <vector <int> > dp(t, vector <int> (1e5 + 1));
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = st1[i - 1] * q % const1;
    	st2[i] = st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = dp[0][i - 1] * q % const1;
    	dp[0][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		if(it == dp.size())
    		{
    			cout << "A";
    			return 0;
    		}
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = dp[it][i - 1] * q % const1;
    			dp[it][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int const1 = 1e9 + 7;
vector <int> fact(1e5 + 1), fact1(1e5 + 1);
int power(int a, int b)
{
	if(b == 0)
	{
		return 1;
	}
	if(b % 2 == 0)
	{
		int t = power(a, b / 2);
		return t * t % const1;
	}
	int t = power(a, b / 2);
	t = t * t % const1;
	return t * a % const1;
}
int cnk(int a, int b){
	return fact[a] * fact1[a - b] % const1 * fact1[b] % const1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    int m;
    cin >> m;
    string s;
    cin >> s;
    fact[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	fact[i] = fact[i - 1] * i % const1;
    }
    fact1[1e5] = power(fact[1e5], const1 - 2);
    for(int i = 1e5 - 1; i >= 0; i--)
    {
    	fact1[i] = fact1[i + 1] * (i + 1) % const1;
    }
    int n = s.size();
    map <int, int> mp;
    mp[n] = 0;
    int t = sqrt(1e5) + 1;
    int q = 26;
    vector <vector <int> > dp(t, vector <int> (1e5 + 1));
    vector <int> st1(1e5 + 1), st2(1e5 + 1);
    st1[0] = 1;
    st2[0] = 1;
    for(int i = 1; i <= 1e5; i++)
    {
    	st1[i] = st1[i - 1] * q % const1;
    	st2[i] = st2[i - 1] * (q - 1) % const1;
    }
    for(int i = n; i <= 1e5; i++)
    {
    	dp[0][i] = dp[0][i - 1] * q % const1;
    	dp[0][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    	if(dp[0][i] >= const1)
    	{
    		dp[0][i] -= const1;
    	}
    }
    int it = 0;
    while(m--)
    {
    	int type;
    	cin >> type;
    	if(type == 1)
    	{
    		string s;
    		cin >> s;
    		n = s.size();
    		if(mp.count(n))
    		{
    			continue;
    		}
    		it++;
    		mp[n] = it;
    		if(it > dp.size())
    		{
    			cout << "A";
    			return 0;
    		}
    		for(int i = n; i <= 1e5; i++)
    		{
    			dp[it][i] = dp[it][i - 1] * q % const1;
    			dp[it][i] += cnk(i - 1, n - 1) * st2[i - n] % const1;
    			if(dp[it][i] >= const1)
    			{
    				dp[it][i] -= const1;
    			}
    		}
    	}
    	else
    	{
    		int n1;
    		cin >> n1;
    		cout << dp[mp[n]][n1] << "\n";
    	}
    }
	return 0;
}


// Problem : C. Mortal Kombat Tower
// Contest : Codeforces - Educational Codeforces Round 95 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1418/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;

typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;

typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;

#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 200001; //check the limits, dummy
vi a(MX);
int n;
int dp[2][MX];
//chance 0 if my turn
//chance 1 if friend's turn.
//boss_no represents the position of boss we are at.
int solve(int chance,int boss_no){
	if(boss_no>=n)
	return 0;
	if(dp[chance][boss_no]!=-1)
		return dp[chance][boss_no];
	if(chance){
			return dp[chance][boss_no]=min(a[boss_no]+solve(chance^1,boss_no+1),a[boss_no]+a[boss_no+1]+solve(chance^1,boss_no+2));
	}
		return dp[chance][boss_no]=min(solve(chance^1,boss_no+1),solve(chance^1,boss_no+2));

}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		fill(dp[0],dp[0]+2*MX,-1);
		cin>>n;
		loop(i,n){
			cin>>a[i];
		}
		cout<<solve(1,0)<<cl;
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


// Problem : C. Mortal Kombat Tower
// Contest : Codeforces - Educational Codeforces Round 95 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1418/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;

typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;

typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;

#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 200001; //check the limits, dummy
vi a(MX);
int n;
int dp[2][MX];
//chance 0 if my turn
//chance 1 if friend's turn.
//boss_no represents the position of boss we are at.
int solve(int chance,int boss_no){
	if(boss_no>=n)
	return 0;
	if(dp[chance][boss_no]!=INT_MAX)
		return dp[chance][boss_no];
	if(chance){
		if(boss_no<n-2)
			return dp[chance][boss_no]=min(a[boss_no]+solve(chance^1,boss_no+1),a[boss_no]+a[boss_no+1]+solve(chance^1,boss_no+2));
		return dp[chance][boss_no]=a[boss_no];
	}
	if(boss_no<n-2)
		return dp[chance][boss_no]=min(solve(chance^1,boss_no+1),solve(chance^1,boss_no+2));
	return dp[chance][boss_no]=0;

}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		fill(all(a),0);
		fill(dp[0],dp[0]+2*MX,INT_MAX);
		cin>>n;
		loop(i,n){
			cin>>a[i];
		}
		cout<<solve(1,0)<<cl;
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


// Problem : C. Mortal Kombat Tower
// Contest : Codeforces - Educational Codeforces Round 95 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1418/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;

typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;

typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;

#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 200001; //check the limits, dummy
vi a(MX);
int n;
int dp[2][MX];
//chance 0 if my turn
//chance 1 if friend's turn.
//boss_no represents the position of boss we are at.
int solve(int chance,int boss_no){
    if(boss_no>=n)
    return 0;
    if(dp[chance][boss_no]!=-1)
        return dp[chance][boss_no];
    if(chance){
            return dp[chance][boss_no]=min(a[boss_no]+solve(chance^1,boss_no+1),a[boss_no]+a[boss_no+1]+solve(chance^1,boss_no+2));
    }
        return dp[chance][boss_no]=min(solve(chance^1,boss_no+1),solve(chance^1,boss_no+2));

}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        fill(dp[0],dp[0]+2*(n+1),-1);
        loop(i,n){
            cin>>a[i];
        }
        cout<<solve(1,0)<<cl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
using namespace std;
const ll N=100005;
	    vector<ll> adj[N];
        ll vis[N]={0};
ll n,i,j,k;
void solve()
{
  	cin>>n;
  	ll a[n];
  	rep(i,0,n)
  	cin>>a[i];
  	ll dp[2][n];
  	dp[0][0]=a[0];
  	if(n>1)
  	{
  		dp[0][1]=dp[0][0]+a[1];
  	    dp[1][1]=dp[0][0];
  	}
  	if(n>2)
  	{
  		dp[1][2]=dp[1][1];
  	    dp[0][2]=dp[1][1]+a[2];
  	}
  	rep(i,3,n)
  	{
  		dp[0][i]=min(dp[1][i-1]+a[i],dp[1][i-2]+a[i]+a[i-1]);
  		dp[1][i]=min(dp[0][i-1],dp[0][i-2]);
  	}
  	cout<<min(dp[0][n-1],dp[1][n-1])<<endl;
}
int main() {

	// your code goes here
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
	int t=1,i;
	cin>>t;
	while(t--)
	{
	    solve();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
using namespace std;
const ll N=100005;
	    vector<ll> adj[N];
        ll vis[N]={0};
ll n,i,j,k;
void solve()
{
  	cin>>n;
  	ll a[n];
  	rep(i,0,n)
  	cin>>a[i];
  	ll ans=0,t=0;
  	i=1;
  	while(i<n)
  	{
  		if(a[i]==0)
  			{
  				ans+=(t/3);
  				t=0;
  			}
  		else
  		{
  			t++;
  		}
  		i++;
  	}
  	ans+=(t/3);
  	if(a[0]==1)
  		ans++;
  	cout<<ans<<endl;

}
int main() {

	// your code goes here
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
	int t=1,i;
	cin>>t;
	while(t--)
	{
	    solve();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
using namespace std;
const ll N=100005;
	    vector<ll> adj[N];
        ll vis[N]={0};
ll n,i,j,k;
void solve()
{
  	cin>>n;
  	ll a[n];
  	rep(i,0,n)
  	cin>>a[i];
  	ll ans=0,t=0;
  	for(i=0;i<n;)
  	{
  		if(t)
  		{
  			if((i+1)<n&&a[i+1]==1)
  				i=i+2;
  			else
  				i++;
  			t=!t;
  		}
  		else
  		{
  			if(a[i]==1)
  				ans++;
  			if((i+1)<n&&a[i+1]==0)
  				i=i+2;
  			else
  				i++;
  			t=!t;
  		}
  	}
  	cout<<ans<<endl;

}
int main() {

	// your code goes here
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
	int t=1,i;
	cin>>t;
	while(t--)
	{
	    solve();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
using namespace std;
const ll N=100005;
	    vector<ll> adj[N];
        ll vis[N]={0};
ll n,i,j,k;
void solve()
{
  	cin>>n;
  	ll a[n];
  	rep(i,0,n)
  	cin>>a[i];
  	ll dp[2][n];
  	dp[0][0]=a[0];
  	dp[1][0]=INT_MAX-2;
  	if(n>1)
  	{
  		dp[0][1]=dp[0][0]+a[1];
  	    dp[1][1]=dp[0][0];
  	}
  	rep(i,2,n)
  	{
  		dp[0][i]=min(dp[1][i-1],dp[0][i-1])+a[i];
  		dp[1][i]=min(dp[0][i-1],dp[1][i-1]);
  	}
  	cout<<min(dp[0][n-1],dp[1][n-1])<<endl;
}
int main() {

	// your code goes here
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
	int t=1,i;
	cin>>t;
	while(t--)
	{
	    solve();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
using namespace std;
const ll N=100005;
	    vector<ll> adj[N];
        ll vis[N]={0};
ll n,i,j,k;
void solve()
{
  	cin>>n;
  	ll a[n];
  	rep(i,0,n)
  	cin>>a[i];
  	ll dp[2][n];
  	dp[0][0]=a[0];
  	dp[1][0]=INT_MAX-2;
  	if(n>1)
  	{
  		dp[0][1]=dp[0][0]+a[1];
  	    dp[1][1]=dp[0][0];
  	}
  	rep(i,2,n)
  	{
  		dp[0][i]=min(dp[1][i-1]+a[i],dp[1][i-2]+a[i]+a[i-1]);
  		dp[1][i]=min(dp[0][i-1],dp[0][i-2]);
  	}
  	cout<<min(dp[0][n-1],dp[1][n-1])<<endl;
}
int main() {

	// your code goes here
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
	int t=1,i;
	cin>>t;
	while(t--)
	{
	    solve();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
using namespace std;
const ll N=100005;
	    vector<ll> adj[N];
        ll vis[N]={0};
ll n,i,j,k;
void solve()
{
  	cin>>n;
  	ll a[n];
  	rep(i,0,n)
  	cin>>a[i];
  	ll dp[2][n];
  	dp[0][0]=a[0];
  	dp[1][0]=INT_MAX-2;
  	if(n>1)
  	{
  		dp[0][1]=dp[0][0]+a[1];
  	    dp[1][1]=dp[0][0];
  	}
  	rep(i,2,n)
  	{
  		dp[0][i]=(dp[1][i-1]+a[i]);
  		dp[1][i]=min(dp[0][i-1],dp[0][i-2]);
  	}
  	cout<<min(dp[0][n-1],dp[1][n-1])<<endl;
}
int main() {

	// your code goes here
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
	int t=1,i;
	cin>>t;
	while(t--)
	{
	    solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define mii map<int,int>
#define pqh priority_queue<int>
#define pql priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x);
#define zerobits(x)__builtin_ctzll(x);
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
#define mod 1000000007
int n, a[200005];
int dp[200005][2];
int ok(int i, int turn)
{
	if (i >= n)
		return 0;

	if (dp[i][turn] != -1)
		return dp[i][turn];
	if (turn) {
		int mini = INT_MAX;
		if (i < n and a[i] == 1)
			mini = min(mini, ok(i + 1, turn ^ 1) + 1);
		if (i < n and a[i] == 0)
			mini = min(mini, ok(i + 1, turn ^ 1));
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1));
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 2);
		return dp[i][turn] = mini;

	} else {
		int mini = INT_MAX;
		mini = min(ok(i + 1, turn ^ 1), ok(i + 2, turn ^ 1));
		return dp[i][turn] = mini;
	}

}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//FUCK RATINGS
	//Once a CHARAS, always a CHARAS

	int t; cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		mem(dp, -1);
		ok(0,1);
		cout << dp[0][1] << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define mii map<int,int>
#define pqh priority_queue<int>
#define pql priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x);
#define zerobits(x)__builtin_ctzll(x);
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
#define mod 1000000007
int n, a[200005];
int dp[200005][2];
int ok(int i, int turn)
{
	if (i >= n)
		return 0;

	if (dp[i][turn] != -1)
		return dp[i][turn];
	if (turn) {
		int mini = INT_MAX;
		if (i < n and a[i] == 1)
			mini = min(mini, ok(i + 1, turn ^ 1) + 1);
		if (i < n and a[i] == 0)
			mini = min(mini, ok(i + 1, turn ^ 1));
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1));
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 2);
		return dp[i][turn] = mini;

	} else {
		int mini = INT_MAX;
		mini = min(ok(i + 1, turn ^ 1), ok(i + 2, turn ^ 1));
		return dp[i][turn] = mini;
	}

}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//FUCK RATINGS
	//Once a CHARAS, always a CHARAS

	int t; cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		mem(dp, -1);
		cout << ok(0, 1) << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define mii map<int,int>
#define pqh priority_queue<int>
#define pql priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x);
#define zerobits(x)__builtin_ctzll(x);
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
#define mod 1000000007
int n, a[200001];
int dp[200001][2];
int ok(int i, int turn)
{
	if (i >= n)
		return 0;

	if (dp[i][turn] != -1)
		return dp[i][turn];
	if (turn) {
		int mini = INT_MAX;
		if (i < n and a[i] == 1)
			mini = min(mini, ok(i + 1, turn ^ 1) + 1);
		if (i < n and a[i] == 0)
			mini = min(mini, ok(i + 1, turn ^ 1));
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1));
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 2);
		return dp[i][turn] = mini;

	} else {
		int mini = INT_MAX;
		mini = min(ok(i + 1, turn ^ 1), ok(i + 2, turn ^ 1));
		return dp[i][turn] = mini;
	}

}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//FUCK RATINGS
	//Once a CHARAS, always a CHARAS

	int t; cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		mem(dp, -1);
		cout << ok(0, 1) << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int

int n, a[200005];
int dp[200005][2];
int ok(int i, int turn)
{
	if (i >= n)
		return 0;

	if (dp[i][turn] != -1)
		return dp[i][turn];
	if (turn) {
		int mini = INT_MAX;
		if (i < n and a[i] == 1)
			mini = min(mini, ok(i + 1, turn ^ 1) + 1);
		if (i < n and a[i] == 0)
			mini = min(mini, ok(i + 1, turn ^ 1));
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1));
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 2);
		return dp[i][turn] = mini;

	} else {
		int mini = INT_MAX;
		mini = min(ok(i + 1, turn ^ 1), ok(i + 2, turn ^ 1));
		return dp[i][turn] = mini;
	}

}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//FUCK RATINGS
	//Once a CHARAS, always a CHARAS

	int t; cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		mem(dp, -1);
		cout << ok(0, 1) << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define mii map<int,int>
#define pqh priority_queue<int>
#define pql priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x);
#define zerobits(x)__builtin_ctzll(x);
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
#define mod 1000000007
int n, a[100001];
int dp[100001][2];
int ok(int i, int turn)
{
	if (i >= n)
		return 0;
	if (dp[i][turn] != -1)
		return dp[i][turn];
	if (turn) {
		int mini = INT_MAX;
		if (i < n and a[i] == 1)
			mini = min(mini, ok(i + 1, turn ^ 1) + 1);
		if (i < n and a[i] == 0)
			mini = min(mini, ok(i + 1, turn ^ 1));
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 0 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1));
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 0)
			mini = min(mini, ok(i + 2, turn ^ 1) + 1);
		if (i + 1 < n and a[i] == 1 and a[i + 1] == 1)
			mini = min(mini, ok(i + 2, turn ^ 1) + 2);
		return dp[i][turn] = mini;

	} else {
		int mini = INT_MAX;
		mini = min(ok(i + 1, turn ^ 1), ok(i + 2, turn ^ 1));
		return dp[i][turn] = mini;
	}

}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//FUCK RATINGS
	//Once a CHARAS, always a CHARAS

	int t; cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		mem(dp, -1);
		cout << ok(0, 1) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
    #include <math.h>

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }

    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }

    vector<int>a(200005);
    int dp[200005][2];
    int n;

    int ok(int i, int turn){
        if(i>=n)
            return dp[i][turn]=0;
        if(dp[i][turn]!=-1)
            return dp[i][turn];
        if(turn){
            int mini=1e9;
            if(i<n && a[i]==1)
                mini=min(mini,ok(i+1,turn^1)+1);
            if(i<n && a[i]==0)
                mini=min(mini,ok(i+1,turn^1));
            if(i+1<n && a[i]==0 && a[i+1]==1)
                mini=min(mini,ok(i+2,turn^1)+1);
            if(i+1<n && a[i]==0 && a[i+1]==0)
                mini=min(mini,ok(i+2,turn^1));
            if(i+1<n && a[i]==1 && a[i+1]==0)
                mini=min(mini,ok(i+2,turn^1)+1);
            if(i+1<n && a[i]==1 && a[i+1]==1)
                mini=min(mini,ok(i+2,turn^1)+2);
            return dp[i][turn]=mini;
        }
        else{
            int mini=1e9;
            mini=min(ok(i+1,turn^1),ok(i+2,turn^1));
            return dp[i][turn]=mini;
        }
    }

    void solve (){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        memset(dp,-1,sizeof(dp));
        ok(0,1);
        cout<<dp[0][1]<<"\n";

    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)

#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e8;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000-100;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)

#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e9;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n+3,0);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)
#define int long long int
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e8;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	int t;
	cin>>t;
	vector<int> ans;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000-100;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		ans.push_back(go(0,1));
	}
	ff((int)ans.size()) cout<<ans[i]<<"\n";
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)

#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e9;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n+3,0);
		ff(n) cin>>vec[i];
		for(int i=0;i<=n+1;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)
#define int long long int
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e8;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000-100;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)

#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e8;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n+3,0);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000-100;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)
#define int long long int
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e8;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000-100;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)

#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define s second
#define f first
using namespace std;
std::vector<int> vec; int n;
int dp[300000][2];
int go (int idx,int turn ){
	if(idx>=n) return 0;
	int &ans=dp[idx][turn];
	if(ans!=-1) return ans;
	ans = 1e8;
	if(!turn){
		ans = min(go(idx+1,1),go(idx+2,1));
	}
	else{
		ans = min(vec[idx]+go(idx+1,0),vec[idx]+vec[idx+1]+go(idx+2,0));
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		vec.clear();
		vec.resize(n+1,0);
		ff(n) cin>>vec[i];
		for(int i=0;i<300000-100;i++){
			dp[i][0]=-1; dp[i][1]=-1;
		}
		cout<<go(0,1)<<"\n";
	}
}


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

 vector<int>a(200005);
    int dp[200005][2];
    int n;

    int ok(int i, int turn){
        if(i>=n)
            return dp[i][turn]=0;
        if(dp[i][turn]!=-1)
            return dp[i][turn];
        if(turn){
            int mini=1e9;
            if(i<n && a[i]==1)
                mini=min(mini,ok(i+1,turn^1)+1);
            if(i<n && a[i]==0)
                mini=min(mini,ok(i+1,turn^1));

            if(i+1<n && a[i]==0 && a[i+1]==1)
                mini=min(mini,ok(i+2,turn^1)+1);

            if(i+1<n && a[i]==0 && a[i+1]==0)
                mini=min(mini,ok(i+2,turn^1));

            if(i+1<n && a[i]==1 && a[i+1]==0)
                mini=min(mini,ok(i+2,turn^1)+1);

            if(i+1<n && a[i]==1 && a[i+1]==1)
                mini=min(mini,ok(i+2,turn^1)+2);

            return dp[i][turn]=mini;
        }
        else{
            int mini=1e9;
            mini=min(ok(i+1,turn^1),ok(i+2,turn^1));
            return dp[i][turn]=mini;
        }
    }

    void solve (){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        memset(dp,-1,sizeof(dp));
        ok(0,1);
        cout<<dp[0][1]<<"\n";

    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);

        int t=1;
        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


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

vector<int>a(200005);
int dp[200005][2];
int n;

int min_turn(int i,int turn)
{
	if(i>=n)
		return dp[i][0]=0;

	if(dp[i][turn]!=-1)
	     return dp[i][turn];

	if(turn==1)
	{
		int mini=1e9;

		if(i<n && a[i]==1)
		   mini=min(mini,min_turn(i+1,turn^1)+1);

		if(i<n && a[i]==0)
		    mini=min(mini,min_turn(i+1,turn^1));

		if(i+1<n && a[i]==0 && a[i+1]==0)
		   mini=min(mini,min_turn(i+2,turn^1)+1);

		if(i+1<n && a[i]==1 && a[i+1]==0)
		   mini=min(mini,min_turn(i+2,turn^1)+1);

		   if(i+1<n && a[i]==0 && a[i+1]==1)
		   mini=min(mini,min_turn(i+2,turn^1)+1);

		   if(i+1<n && a[i]==1 && a[i+1]==1)
		   mini=min(mini,min_turn(i+2,turn^1)+2);

		   return dp[i][turn]=mini;

			 }

			 else
			 {
			 	int mini=1e9;
			 	mini=min(min_turn(i+1,turn^1),min_turn(i+2,turn^1));

			 	return dp[i][turn]=mini;
			 }
}

int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		cin>>n;

		for(int i=0;i<n;i++)
		cin>>a[i];

		memset(dp,-1,sizeof(dp));

		min_turn(0,1);

		cout<<dp[0][1]<<endl;
	}

	return 0;
}


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

vector<int>a(200005);
int dp[200005][2];
int n;

int min_turn(int i,int turn)
{
	if(i>=n)
		return dp[i][0]=0;

	if(dp[i][turn]!=-1)
	     return dp[i][turn];

	if(turn==1)
	{
		int mini=1e9;

		if(i<n && a[i]==1)
		   mini=min(mini,min_turn(i+1,turn^1)+1);

		if(i<n && a[i]==0)
		    mini=min(mini,min_turn(i+1,turn^1));

		if(i+1<n && a[i]==0 && a[i+1]==0)
		   mini=min(mini,min_turn(i+2,turn^1)+1);

		if(i+1<n && a[i]==1 && a[i+1]==0)
		   mini=min(mini,min_turn(i+2,turn^1)+1);

		   if(i+1<n && a[i]==1 && a[i+1]==1)
		   mini=min(mini,min_turn(i+2,turn^1)+2);

		   return dp[i][turn]=mini;

			 }

			 else
			 {
			 	int mini=1e9;
			 	mini=min(min_turn(i+1,turn^1),min_turn(i+2,turn^1));

			 	return dp[i][turn]=mini;
			 }
}

int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		cin>>n;

		for(int i=0;i<n;i++)
		cin>>a[i];

		memset(dp,-1,sizeof(dp));

		min_turn(0,1);

		cout<<dp[0][1]<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
     ios::sync_with_stdio(false);
     cin.tie(NULL);

  int t;
  cin>>t;

  while(t--)
  {
  	int n;
  	cin>>n;

  	vector<int>a(n);

  	for(int i=0;i<n;i++)
  	cin>>a[i];

  	int i=0,k=0,coin=0;
  	while(i<n)
  	{
  		if(k==0)
  		{
  			if(a[i]==0 && a[i+1]==0)
  			i+=2;

  			else if(a[i]==0 && a[i+1]==1)
  			i+=1;

  			else if(a[i]==1 && a[i+1]==0)
  			{
  				i+=2;
  				coin++;
			  }

			  else
			  {
			  	i+=1;
			  	coin++;
			  }

			  k=1;
		  }

		  else
		  {

		  		if(a[i]==0 && a[i+1]==0)
  		       	i+=1;

  			else if(a[i]==0 && a[i+1]==1)
  			i+=2;

  			else if(a[i]==1 && a[i+1]==0)
  				i+=1;

			  else
			  	i+=2;

		  	k=0;
		  }
	  }

	  cout<<coin<<"\n";
  }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
     ios::sync_with_stdio(false);
     cin.tie(NULL);

  int t;
  cin>>t;

  while(t--)
  {
  	int n;
  	cin>>n;

  	vector<int>a(n);

  	for(int i=0;i<n;i++)
  	cin>>a[i];

  	int i=0,k=0,coin=0;
  	while(i<n)
  	{
  		if(k==0)
  		{
  			if(i==n-1)
		  	{
		  		if(a[i]==1)
		  		coin++;

		  		break;
			  }

  			else if(a[i]==0 && a[i+1]==0)
  			i+=2;

  			else if(a[i]==0 && a[i+1]==1)
  			i+=1;

  			else if(a[i]==1 && a[i+1]==0)
  			{
  				i+=2;
  				coin++;
			  }

			  else
			  {
			  	i+=1;
			  	coin++;
			  }

			  k=1;
		  }

		  else
		  {

		  	if(i==n-1)
		  	i++;

		  	else if(a[i]==0 && a[i+1]==0)
  		       	i+=1;

  			else if(a[i]==0 && a[i+1]==1)
  			i+=2;

  			else if(a[i]==1 && a[i+1]==0)
  				i+=1;

			  else
			  	i+=2;

		  	k=0;
		  }
	  }

	  cout<<coin<<"\n";
  }
    return 0;
}


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

int n;
int dp[200005][2];

vector<int>a(200005);

int ok(int i,int turn)
{
	if(i>=n)
	return dp[i][turn]=0;

	if(dp[i][turn]!=-1)
	return dp[i][turn];

	if(turn==1)
	{
		int minm=1e9;

		if(i<n && a[i]==0)
		minm=min(minm,ok(i+1,turn^1));

		if(i<n && a[i]==1)
		minm=min(minm,ok(i+1,turn^1)+1);

		if(i+1<n && a[i]==0 && a[i+1]==1)
		minm=min(minm,ok(i+2,turn^1)+1);

		if(i+1<n && a[i]==0 && a[i+1]==0)
		minm=min(minm,ok(i+2,turn^1));

		if(i+1<n && a[i]==1 && a[i+1]==0)
		minm=min(minm,ok(i+2,turn^1)+1);

		if(i+1<n && a[i]==1 && a[i+1]==1)
		minm=min(minm,ok(i+2,turn^1)+2);

		return dp[i][turn]=minm;
	}

	else
	{
		int minm=1e9;

		minm=min(ok(i+1,turn^1),ok(i+2,turn^1));

		return dp[i][turn]=minm;
	}
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;

		memset(dp,-1,sizeof(dp));

		for(int i=0;i<n;i++)
		cin>>a[i];

		ok(0,1);

		cout<<dp[0][1]<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn=2e5+10;

int n,a[maxn],dp[maxn][2];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),dp[n][1]=dp[n][0]=n;
		dp[1][0]=a[1];
		dp[2][0]=a[1]+a[2];
		dp[2][1]=a[1];
		for(int i=3;i<=n;i++){
			for(int j=0;j<2;j++){
				int sum=0;
				for(int k=1;k<=2;k++){
					sum+=a[i-k+1]*(1-j);
					dp[i][j]=min(dp[i][j],dp[i-k][j^1]+sum);
				}
			}
		}
		cout<<min(dp[n][1],dp[n][0])<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn=5e5+10;

int n,a[maxn],b[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		int cur=1,cnt=0,ans=0;
		for(int i=1;i<=n;i++){
			if(cur==1){
				if(!a[i]) cnt++;
				else{
					if(!cnt) cnt++,ans++;
					else cnt=1,cur=0;
				}
			}
			else{
				if(!a[i]){
					if(!cnt) cnt++;
					else cnt=1,cur=1;
				}
				else cnt++;
			}
			if(cnt==2) cur^=1,cnt=0;
			//cout<<cur<<" "<<cnt<<endl;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn=2e5+10;

int n,a[maxn];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		int res=(a[1]==1);
		for(int i=2;i<=n;i++){
			if(!a[i]) continue;
			int pos=i;
			while(a[i]==1&&i<=n) i++;
			res+=(i-pos)/3;
		}
		cout<<res<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn=2e5+10;

int n,a[maxn],dp[maxn][2];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),dp[i][1]=dp[i][0]=n;
		dp[1][0]=a[1];
		dp[2][0]=a[1]+a[2];
		dp[2][1]=a[1];
		for(int i=3;i<=n;i++){
			for(int j=0;j<2;j++){
				int sum=0;
				for(int k=1;k<=2;k++){
					sum+=a[i-k+1]*(1-j);
					dp[i][j]=min(dp[i][j],dp[i-k][j^1]+sum);
				}
			}
		}
		cout<<min(dp[n][1],dp[n][0])<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define VI vector <int>
#define ss second
#define pii pair<int, int>
#define pci pair<char, int>
#define mii map<int, int>
#define mci map<char, int>
#define fill(a,b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265

int lcm(ll a, ll b){
    ll g=__gcd(a, b);
    return a/g*b;
}

int main() {
    IOS;
	int t;
	t=1;
	cin>>t;
	while (t--){
	    int n;
	    cin>>n;
	    int a[n];
	    for (int i=0; i<n; i++) cin>>a[i];
	    int cnt=0;
	    bool b=true;
	    int i;
	    for (i=0; i<n; i++){
	        if (a[i]){
	            if (b){
	                cnt++;
	                if (a[i+1]==0) i++;
	            }
	            else{
	                if (a[i+1]) i++;
	            }
	        }
	        else{
	            if (b){
	                if (a[i+1]==0) i++;
	            }
	            else{
	                if (a[i+1]) i++;
	            }
	        }
	        b=!b;
	    }
	   // if (i==n-1 && a[i] && b) cnt++;
	    cout<<cnt<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define VI vector <int>
#define ss second
#define pii pair<int, int>
#define pci pair<char, int>
#define mii map<int, int>
#define mci map<char, int>
#define fill(a,b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265

int lcm(ll a, ll b){
    ll g=__gcd(a, b);
    return a/g*b;
}

int main() {
    IOS;
	int t;
	t=1;
	cin>>t;
	while (t--){
	    int n;
	    cin>>n;
	    int a[n];
	    for (int i=0; i<n; i++) cin>>a[i];
	    int cnt=0;
	    bool b=true;
	    int i;
	    for (i=0; i<n-1; i++){
	        if (a[i]){
	            if (b){
	                cnt++;
	                if (a[i+1]==0) i++;
	            }
	            else{
	                if (a[i+1]) i++;
	            }
	        }
	        else{
	            if (b){
	                if (a[i+1]==0) i++;
	            }
	            else{
	                if (a[i+1]) i++;
	            }
	        }
	        b=!b;
	    }
	   // if (i==n-1 && a[i] && b) cnt++;
	    cout<<cnt<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define VI vector <int>
#define ss second
#define pii pair<int, int>
#define pci pair<char, int>
#define mii map<int, int>
#define mci map<char, int>
#define fill(a,b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265
const long long N=200005;
int lcm(ll a, ll b){
    ll g=__gcd(a, b);
    return a/g*b;
}
int dp[N][2];
int n;
int a[N];
int solve(int i, int b){
    if (i==n) return 0;
    if (dp[i][b]!=-1) return dp[i][b];
    int c1=0;
    if (a[i]==1 && b==1) c1++;
    int c2=c1;
    if (i<n-1 && a[i+1] && b) c2++;
    return dp[i][b]=min(c1+solve(i+1, 1-b), c2+solve(i+2, 1-b));
}
int main() {
    IOS;
	int t;
	t=1;
	cin>>t;
	while (t--){
	    cin>>n;
	    for (int i=0; i<n; i++) cin>>a[i];
	    for (int i=0; i<n; i++){
	        dp[i][0]=-1;
	        dp[i][1]=-1;
	    }
	    cout<<solve(0, 1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define VI vector <int>
#define ss second
#define pii pair<int, int>
#define pci pair<char, int>
#define mii map<int, int>
#define mci map<char, int>
#define fill(a,b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265
const long long N=200005;
int lcm(ll a, ll b){
    ll g=__gcd(a, b);
    return a/g*b;
}
int dp[N][2];
int n;
int a[N];
int solve(int i, int b){
    if (i==n) return 0;
    if (dp[i][b]!=-1) return dp[i][b];
    int c1=0;
    if (a[i]==1 && b==1) c1++;
    int c2=c1;
    if (i<n-1 && a[i+1] && b) c2++;
    return dp[i][b]=min(c1+solve(i+1, 1-b), c2+solve(i+2, 1-b));
}
int main() {
    IOS;
	int t;
	t=1;
	cin>>t;
	while (t--){
	    cin>>n;
	    for (int i=0; i<n; i++) cin>>a[i];
	    fill (dp, -1);
	    cout<<solve(0, 1)<<endl;
	}
	return 0;
}


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

#define ll long long
#define mod 1000000007
#define ff first
#define ss second
#define pii pair<int,int>
#define pb push_back
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL);
#define endl '\n'
int dp[200002][2][2];
int solve(vector<int>&a, int i, int j, int k){
    if(i==a.size())
    return 0;

    if(dp[i][j][k]!=-1)
    return dp[i][j][k];

    int cost=0;
    if(a[i]==1 && j==0){
        cost++;
    }

    if(k==0){
        return dp[i][j][k]=cost + min(solve(a,i+1,j,1), solve(a,i+1,j^1,0));
    }
    return dp[i][j][k]=cost + solve(a,i+1,j^1,k^1);
}
void tests(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    for (int i=0; i<n; i++){
        dp[i][0][0]=-1;
        dp[i][1][0]=-1;
        dp[i][0][1]=-1;
        dp[i][1][1]=-1;
    }
    cout<<solve(a,0,0,0)<<endl;
}
int main( int argc , char ** argv ){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	ll t = 1;
	cin>>t;
	while(t--){
		tests();
	}
 	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define VI vector <int>
#define ss second
#define pii pair<int, int>
#define pci pair<char, int>
#define mii map<int, int>
#define mci map<char, int>
#define fill(a,b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265

int lcm(ll a, ll b){
    ll g=__gcd(a, b);
    return a/g*b;
}

int main() {
    IOS;
	int t;
	t=1;
	cin>>t;
	while (t--){
	    int n;
	    cin>>n;
	    int a[n];
	    for (int i=0; i<n; i++) cin>>a[i];
	    int cnt=0;
	    bool b=true;
	    int i;
	    for (i=0; i<n-1; i++){
	        if (a[i]){
	            if (b){
	                if (a[i+1]==0) i++;
	                cnt++;
	            }
	            else{
	                if (a[i+1]) i++;
	            }
	        }
	        else{
	            if (b){
	                if (a[i+1]==0) i++;
	            }
	            else{
	                if (a[i+1]) i++;
	            }
	        }
	        b=!b;
	    }
	    if (i==n-1 && a[i] && b) cnt++;
	    cout<<cnt<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define VI vector <int>
#define ss second
#define pii pair<int, int>
#define pci pair<char, int>
#define mii map<int, int>
#define mci map<char, int>
#define fill(a,b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265
const long long N=200005;
int lcm(ll a, ll b){
    ll g=__gcd(a, b);
    return a/g*b;
}
int dp[N][2];
int n;
int a[N];
int solve(int i, int b){
    if (i==n) return 0;
    if (dp[i][b]!=-1) return dp[i][b];
    int c1=0;
    if (a[i]==1 && b==1) c1++;
    int c2=c1;
    if (i<n-1 && a[i+1] && b) c2++;
    return dp[i][b]=min(c1+solve(i+1, b^1), c2+solve(i+2, b^1));
}
int main() {
    IOS;
	int t;
	t=1;
	cin>>t;
	while (t--){
	    cin>>n;
	    for (int i=0; i<n; i++) cin>>a[i];
	    fill (dp, -1);
	    cout<<solve(0, 1)<<endl;
	}
	return 0;
}


#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isPrime(ll n)
{
    if (n<=1)  return false;
    if (n<=3)  return true;
    if (n%2==0||n%3==0) return false;
    for(ll i=5; i*i<=n; i+=6)
        if (n%i==0||n%(i+2)==0) return false;

    return true;
}
/********************************************************************************************/
ll n, arr[200005];
ll dp[200005][2];
ll cal(ll indx, int turn)
{
    if(indx>n) return 0;
    if(dp[indx][turn]!=-1) return dp[indx][turn];
    if(turn)
    {
        ll x=arr[indx];
        if(indx<n)
        {
            ll y=x+arr[indx+1];
            return dp[indx][turn]=min(x+cal(indx+1,0),y+cal(indx+2,0));
        }
        else return dp[indx][turn]=(x+cal(indx+1,0));
    }
    else
    {
        if(indx<n) return dp[indx][turn]=min(cal(indx+1,1),cal(indx+2,1));
        else return dp[indx][turn]=cal(indx+1,1);
    }
}
void solve()
{
    cin>>n;
    rep(i,1,n+1) cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<cal(1,1)<<"\n";
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isPrime(ll n)
{
    if (n<=1)  return false;
    if (n<=3)  return true;
    if (n%2==0||n%3==0) return false;
    for(ll i=5; i*i<=n; i+=6)
        if (n%i==0||n%(i+2)==0) return false;

    return true;
}
/********************************************************************************************/
ll n, arr[200005];
ll dp[200005][2];
ll cal(ll indx, int turn)
{
    if(indx>n) return 0;
    if(dp[indx][turn]!=-1) return dp[indx][turn];
    if(turn)
    {
        ll a1,a2;
        if(indx<n) a2=(arr[indx]+arr[indx+1]+cal(indx+2,0));
        else a1=(arr[indx]+cal(indx+1,0));
        return dp[indx][turn]=min(a1,a2);
    }
    else
    {
        ll a1,a2;
        if(indx<n) a1=cal(indx+2,1);
        else return a2=cal(indx+1,1);
        return dp[indx][turn]=min(a1,a2);
    }
}
void solve()
{
    cin>>n;
    rep(i,1,n+1) cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<cal(1,1)<<"\n";
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isPrime(ll n)
{
    if (n<=1)  return false;
    if (n<=3)  return true;
    if (n%2==0||n%3==0) return false;
    for(ll i=5; i*i<=n; i+=6)
        if (n%i==0||n%(i+2)==0) return false;

    return true;
}
/********************************************************************************************/
ll n, arr[200005];
ll dp[200005][2];
ll cal(ll indx, int turn)
{
    if(indx>n) return 0;
    if(dp[indx][turn]!=-1) return dp[indx][turn];
    if(turn)
    {
        ll a1,a2=INT_MAX;
        if(indx<n) a2=(arr[indx]+arr[indx+1]+cal(indx+2,0));
        a1=(arr[indx]+cal(indx+1,0));
        return dp[indx][turn]=min(a1,a2);
    }
    else
    {
        ll a1,a2=INT_MAX;
        if(indx<n) a2=cal(indx+2,1);
        a1=cal(indx+1,1);
        return dp[indx][turn]=min(a1,a2);
    }
}
void solve()
{
    cin>>n;
    rep(i,1,n+1) cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<cal(1,1)<<"\n";
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isPrime(ll n)
{
    if (n<=1)  return false;
    if (n<=3)  return true;
    if (n%2==0||n%3==0) return false;
    for(ll i=5; i*i<=n; i+=6)
        if (n%i==0||n%(i+2)==0) return false;

    return true;
}
/********************************************************************************************/
ll n, arr[200005];
ll dp[200005][2];
ll cal(ll indx, int turn)
{
    if(indx>n) return 0;
    if(dp[indx][turn]!=-1) return dp[indx][turn];
    if(turn)
    {
        ll x=arr[indx],a1,a2;
        if(indx<n)
        {
            ll y=x+arr[indx+1];
            a2=min(x+cal(indx+1,0),y+cal(indx+2,0));
        }
        else a1=(x+cal(indx+1,0));
        return dp[indx][turn]=min(a1,a2);
    }
    else
    {
        ll a1,a2;
        if(indx<n) a1=min(cal(indx+1,1),cal(indx+2,1));
        else return a2=cal(indx+1,1);
        return dp[indx][turn]=min(a1,a2);
    }
}
void solve()
{
    cin>>n;
    rep(i,1,n+1) cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<cal(1,1)<<"\n";
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isPrime(ll n)
{
    if (n<=1)  return false;
    if (n<=3)  return true;
    if (n%2==0||n%3==0) return false;
    for(ll i=5; i*i<=n; i+=6)
        if (n%i==0||n%(i+2)==0) return false;

    return true;
}
/********************************************************************************************/
ll n, arr[200005];
ll dp[200005][2];
ll cal(ll indx, int turn)
{
    if(indx>n) return 0;
    if(dp[indx][turn]!=-1) return dp[indx][turn];
    if(turn)
    {
        ll a1,a2=INT_MAX;
        if(indx<n) a2=(arr[indx]+arr[indx+1]+cal(indx+2,0));
        a1=(arr[indx]+cal(indx+1,0));
        return dp[indx][turn]=min(a1,a2);
    }
    else
    {
        ll a1,a2=INT_MAX;
        if(indx<n) a2=cal(indx+2,1);
        a1=cal(indx+1,1);
        return dp[indx][turn]=min(a1,a2);
    }
}
void solve()
{
    cin>>n;
    rep(i,1,n+1) cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<cal(1,1)<<"\n";
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}