    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
	#if DEBUG
    	#include "debug.h"
	#else
    	#define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
    	//ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
    	#ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
        	 int n;LL int s;
        	 cin>>n>>s;
        	 LL int a[n],ss;ss=0;int tt=0;
        	 fin{
        	 	cin>>a[i];if(a[i]<=s){
        	 		tt=1;
        	 	}
        	 	ss=ss+a[i];
        	 }
        	 if(ss<=s){
        	 	cout<<0<<endl;
        	 }else{
        	 	LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
        	 	st[0]=a[0];
        	 	for(int i=0;i<n-1;i++){
        	 		st[i+1]=st[i]+a[i+1];
        	 		if(a[i]>maxx){
        	 			maxx=a[i];pos=i+1;
        	 		}
        	 		if(st[i]>s){
        	 			break;
        	 		}
        	 	}if(a[0]>=a[pos-1]&&tt==1){
        	 		cout<<1<<endl;
        	 	}else{if(pos!=-1&&tt==1)
        	 		cout<<pos<<endl;
        	 		else{
        	 			cout<<0<<endl;
        	 		}
        	 	}
        	 }
        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n;LL int s;
             cin>>n>>s;
             LL int a[n],ss;ss=0;int tt=0;
             fin{
                cin>>a[i];if(a[i]<=s){
                    tt=1;
                }
                ss=ss+a[i];
             }
             if(ss<=s){
                cout<<0<<endl;
             }else{
                LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
                st[0]=a[0];
                for(int i=0;i<n-1;i++){
                    st[i+1]=st[i]+a[i+1];
                    if(a[i]>maxx){
                        maxx=a[i];pos=i+1;
                    }
                    if(st[i+1]>s){
                        break;
                    }
                }if(a[0]>=a[pos-1]&&tt==1){
                    cout<<1<<endl;
                }else{if(pos!=-1&&tt==1)
                    cout<<pos<<endl;
                    else{
                        cout<<0<<endl;
                    }
                }
             }
        }
    }


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
		continue;
	}
	if(u == t)u--;
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
		continue;
	}
	u--;
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans >= s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		o = 0;
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;

			}
		}
		if(u == p)
		cout<<0<<endl;
		else cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
		continue;
	}
	u++;
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		o = 0;
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;

			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		o = 0;
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;

			}
		}
		if(u == p)
		cout<<0<<endl;
		else cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s){
			u = j;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);
			if(mx = a[g]&&o == 0){
				m = g;
				o++;
			}
		}
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;
			}
		}

		if(u == p-1)
		cout<<0<<endl;
		else cout<<p-1<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){
			int a;
			cin >> a;
			ans+=a;
			if(mx <= a)
			{
			u = j;
			}
			mx = max(a,mx);
		}
		if(ans <= s)
		cout<<0<<endl;
		else cout<<u<<endl;
		ans = 0;
		mx = 0;

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		o = 0;
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;

			}
		}
		if(u == p)
		cout<<0<<endl;
		else cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s){
			u = j - 1;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u + 1 >= g;g++){
			mx = max(mx,a[g]);
			if(mx = a[g]&&o == 0){
				m = g;
				o++;
			}
		}
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;
			}
		}

		if(u == p-1)
		cout<<0<<endl;
		else cout<<p-1<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx = a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;
			}
		}
		if(u == p+1)
		cout<<0<<endl;
		else cout<<p-1<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans >= s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s){
			u = j - 1;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u + 1 >= g;g++){
			mx = max(mx,a[g]);
			if(mx = a[g]&&o == 0){
				m = g;
				o++;
			}
		}
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;
			}
		}

		if(u == p-1)
		cout<<0<<endl;
		else cout<<p-1<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s){
			u = j;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u + 1 >= g;g++){
			mx = max(mx,a[g]);
			if(mx = a[g]&&o == 0){
				m = g;
				o++;
			}
		}
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;
			}
		}

		if(u == p-1)
		cout<<0<<endl;
		else cout<<p-1<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		o = 0;
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;

			}
		}
		if(u == p)
		cout<<0<<endl;
		else cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0''
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
				o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
		continue;
	}

		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans >= s&&b == 0){
			u = j;
			b++;
		}
	}
	if(u == 0){
		cout<<0<<endl;
		continue;
	}
		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
		o = 0;
		for(int y = 1;t >= y;y++ ){
			if(m != y)
			cnt+=a[y];
			if(cnt <= s){
				p = y;

			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mx;
int u;
int ans;
int a[101010];
int cnt;
int o,b;
int p;
int m;

int main(){
	int n;
	cin >> n;
	for(int i = 1;n >= i;i++){
		int t,s;
		cin >> t >> s;
		for(int j = 1;t >= j;j++){

			cin >> a[j];
			ans+=a[j];
		if(ans > s&&b == 0){
			u = j;
			b++;
		}
	}
	if(b == 0){
		cout<<0<<endl;
		continue;
	}

		for(int g = 1;u  >= g;g++){
			mx = max(mx,a[g]);

		}
			for(int v = 1;u  >= v;v++){
			if(mx == a[v]&&o == 0){
				m = v;
				o++;
			}
		}
 cout<<m<<endl;
		o = 0;
		mx = 0;
		cnt = 0;
		ans = 0;
		u = 0;
		m = 0;
		b = 0;
		p = 0;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = lower_bound(segs.begin(), segs.end(), s + A[i]);
            if((*it) > s + A[i]) it--;
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = lower_bound(segs.begin(), segs.end(), s + A[i]);
            if(it != segs.end() && (*it) > s + A[i] && it != segs.begin()) it--;
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            int l = 1, r = n, currAns = -1;
            while(l <= r) {
                int mid = (l + r) / 2;

                if((i <= mid && pre[mid] - A[i] <= s) || (mid < i && pre[mid] <= s)) {
                    currAns = mid;
                    l = mid + 1;
                }else {
                    r = mid - 1;
                }
            }

            if(currAns == -1) continue;
            if(currAns > maxDiff) {
                maxDiff = currAns;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            int l = 1, r = n, currAns = -1;
            while(l <= r) {
                int mid = (l + r) / 2;

                if(pre[mid] <= s + A[i]) {
                    currAns = mid;
                    l = mid + 1;
                }else {
                    r = mid - 1;
                }
            }

            if(currAns == -1) continue;
            if(currAns > maxDiff) {
                maxDiff = currAns;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = upper_bound(segs.begin(), segs.end(), s + A[i]);
            if(it == segs.begin()) continue;
            it--;
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = lower_bound(segs.begin(), segs.end(), s + A[i]);
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = lower_bound(segs.begin(), segs.end(), s + A[i]);
            if(it == segs.end() || ((*it) > s + A[i] && it != segs.begin())) it--;
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = upper_bound(segs.begin(), segs.end(), s + A[i]);
            it--;
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            auto it = lower_bound(segs.begin(), segs.end(), s + A[i]);
            if((*it) > s + A[i] && it != segs.begin()) it--;
            ll diff = it - segs.begin();
            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N], pre[N];

int main(){
    fIO

    int t;
    cin >> t;

    while(t--) {
        int n;
        ll s;
        cin >> n >> s;
        pre[0] = 0;

        vector<ll> segs;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            pre[i] = pre[i - 1] + A[i];
            segs.pb(pre[i]);
        }

        ll ans = 0, maxDiff = 0;
        for(int i = 1; i <= n; i++) {
            ll sum = pre[i];
            auto it = lower_bound(segs.begin(), segs.end(), s + A[i]);

            if(it != segs.end() && it != segs.begin() && (*it) > s + A[i]) it--;
            else if(it == segs.begin() && (*it) > s) it = segs.begin();
            else if(pre[n] - A[i] <= s) it--;

            ll diff = it - segs.begin();

            if(diff > maxDiff) {
                maxDiff = diff;
                ans = i;
            }
        }
        if(pre[n] <= s) cout << "0\n";
        else cout << ans << "\n";
    }
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        boost
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (t) continue;
            q += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
                w = i;
            }
            if (q >= m)
            {
                t = 1;
            }
        }
        if (t == 0) cout << 0 << '\n';
        else cout << w << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

pair <ll, ll> a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i].ff;
            a[i].ss = i;
        }
        for (ll i = 1; i <= n; ++i)
        {
            q += a[i].ff;
            if (q > m) {w = i; break;}
        }
        sort(a + 1, a + w + 1);
        if (q == m) cout << 0 << '\n';
        else cout << a[w].ss << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (t) continue;
            q += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
                w = i;
            }
            if (q >= m)
            {
                t = 1;
            }
        }
        if (t == 0) cout << 0 << '\n';
        else cout << w << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

pair <ll, ll> a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i].ff;
            a[i].ss = i;
        }
        for (ll i = 1; i <= n; ++i)
        {
            q += a[i];
            if (q > m) {w = i; break;}
        }
        sort(a + 1, a + w + 1);
        if (q == m) cout << 0 << '\n';
        else cout << a[w].ss << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (t) continue;
            q += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
                w = i;
            }
            if (q > m)
            {
                t = 1;
            }
        }
        if (t == 0) cout << 0 << '\n';
        else if (a[w + 1] > mx) cout << w + 1 << '\n';
        else cout << w << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (t) continue;
            q += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
                w = i;
            }
            if (q >= m)
            {
                t = 1;
                q -= a[i];
            }
        }

        cout << w << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (t) continue;
            q += a[i];
            if (q > m) t = 1;
            if (a[i] > mx)
            {
                mx = a[i];
                w = i;
            }
        }
        if (t == 0) cout << 0 << '\n';
        else if (a[w + 1] > mx) cout << w + 1 << '\n';
        else cout << w << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, mx = 0, q = 0, id = 0;
        cin >> n >> m;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (a[i] >= m) break;
            q += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
                id = i;
            }
        }
        if (q <= m) cout << 0 << '\n';
        else
        {
            cout << id << '\n';
        }

    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    boost
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            q += a[i];
            if (q >= m && !t)
            {
                t = 1;
                q -= a[i];
                ans = i;
            }
        }
        cout << ans << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, t = 0, q = 0, cnt = 0, w = 0;
        cin >> n >> m;
        ll ans = 0, mx = 0;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (t) continue;
            q += a[i];
            if (q > m) t = 1;
            if (a[i] > mx)
            {
                mx = a[i];
                w = i;
            }
        }
        if (q == m) cout << 0 << '\n';
        else if (a[w + 1] > mx) cout << w + 1 << '\n';
        else cout << w << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD % 1000000007

using namespace std;

const ll N = 1e5 + 10;
const ll inf = 1e18 + 10;

ll a[N];

signed main()
{
    boost
    ll q;
    cin >> q;
    for (ll k = 1; k <= q; ++k)
    {
        ll n, m, mx = 0, q = 0, id = 0;
        cin >> n >> m;
        for (ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            if (a[i] >= m) continue;
            q += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
                id = i;
            }
        }
        if (q <= m) cout << 0 << '\n';
        else
        {
            cout << id << '\n';
        }

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            if (sum+mass[j]<=s)
            {
                sum+=mass[j];
                index=j;
            }
        }
        if (index+1==n)
        {
            cout << "0" << "\n";
            return 0;
        }
        index++;
        max_element_=mass[0];
        index_ans=0;
        for (long long j=0; j<index; j++)
        {
            if (max_element_<mass[j])
            {
                max_element_=mass[j];
                index_ans=j;
            }
        }
        if (index+2<n && mass[index]>=mass[index+1]+mass[index+2])
            cout << index+1;
        else
            cout << index_ans+1 << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[1000000];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            sum+=mass[j];
            index=j;
        }
        if (index+1==n && sum<=s)
        {
            cout << "0" << "\n";
        }
        else
        {
            max_element_=mass[0];
            index_ans=0;
            for (long long j=0; j<=index; j++)
            {
                if (max_element_<mass[j])
                {
                    max_element_=mass[j];
                    index_ans=j;
                }
            }
            for (long long j=0; j<=index; j++)
            {
                if (index+2<n && mass[j]>=mass[index+1]+mass[index+2])
                    index_ans=j;
            }
            cout << index_ans+1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            if (sum+mass[j]<=s)
            {
                sum+=mass[j];
                index=j;
            }
        }
        if (index+1==n)
        {
            cout << "0" << "\n";
            return 0;
        }
        index++;
        max_element_=mass[0];
        index_ans=0;
        for (long long j=0; j<index; j++)
        {
            if (max_element_<mass[j])
            {
                max_element_=mass[j];
                index_ans=j;
            }
        }
        for (long long j=0; j<index; j++)
        {
            if (index+1<n && mass[j]>=mass[index]+mass[index+1])
                index_ans=j;
        }
        cout << index_ans+1 << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            sum+=mass[j];
            index=j;
        }
        cout << sum << " " << index << "\n";
        if (index+1==n && sum<=s)
        {
            cout << "0" << "\n";
        }
        else
        {
            max_element_=mass[0];
            index_ans=0;
            for (long long j=0; j<=index; j++)
            {
                if (max_element_<mass[j])
                {
                    max_element_=mass[j];
                    index_ans=j;
                }
            }
            for (long long j=0; j<=index; j++)
            {
                if (index+2<n && mass[j]>=mass[index+1]+mass[index+2])
                    index_ans=j;
            }
            cout << index_ans+1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            sum+=mass[j];
            index=j;
        }
        if (index+1==n)
        {
            cout << "0" << "\n";
            return 0;
        }
        index++;
        max_element_=mass[0];
        index_ans=0;
        for (long long j=0; j<index; j++)
        {
            if (max_element_<mass[j])
            {
                max_element_=mass[j];
                index_ans=j;
            }
        }
        for (long long j=0; j<=index; j++)
        {
            if (index+2<n && mass[j]>=mass[index+1]+mass[index+2])
                index_ans=j;
        }
        cout << index_ans+1 << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            if (sum+mass[j]<=s)
            {
                sum+=mass[j];
                index=j;
            }
        }
        if (index+1==n)
        {
            cout << "0" << "\n";
            return 0;
        }
        index++;
        max_element_=mass[0];
        index_ans=0;
        for (long long j=0; j<index; j++)
        {
            if (max_element_<mass[j])
            {
                max_element_=mass[j];
                index_ans=j;
            }
        }
        for (long long j=0; j<=index; j++)
        {
            if (index+2<n && mass[j]>=mass[index+1]+mass[index+2])
                index_ans=j;
        }
        cout << index_ans+1 << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            if (sum+mass[j]<=s)
            {
                sum+=mass[j];
                index=j;
            }
        }
        if (index+1==n)
        {
            cout << "0" << "\n";
            return 0;
        }
        index++;
        cout << index << "\n";
        max_element_=mass[0];
        index_ans=0;
        for (long long j=0; j<index; j++)
        {
            if (max_element_<mass[j])
            {
                max_element_=mass[j];
                index_ans=j;
            }
        }
        for (long long j=0; j<index; j++)
        {
            if (index+1<n && mass[j]>=mass[index]+mass[index+1])
                index_ans=j;
        }
        cout << index_ans+1 << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

unsigned long long mass[1000000];

int main()
{
    unsigned long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (unsigned long long j=0; j<n; j++)
            cin >> mass[j];
        for (unsigned long long j=0; j<n && sum<=s ; j++)
        {
            sum+=mass[j];
            index=j;
        }
        if (index+1==n && sum<=s)
        {
            cout << "0" << "\n";
        }
        else
        {
            max_element_=mass[0];
            index_ans=0;
            for (unsigned long long j=0; j<=index; j++)
            {
                if (max_element_<mass[j])
                {
                    max_element_=mass[j];
                    index_ans=j;
                }
            }
            for (unsigned long long j=0; j<=index; j++)
            {
                if (index+2<n && mass[j]>=mass[index+1]+mass[index+2] && sum<=s)
                    index_ans=j;
            }
            cout << index_ans+1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int mass[100001];

int main()
{
    long long s,n,sum=0,t,temp,index,index_ans,max_element_;
    cin >> t;
    for (long long i=0; i<t; i++)
    {
        cin >> n >> s;
        sum=0;
        index=0;
        for (long long j=0; j<n; j++)
            cin >> mass[j];
        for (long long j=0; j<n && sum<=s ; j++)
        {
            if (sum+mass[j]<=s)
            {
                sum+=mass[j];
                index=j;
            }
        }
        if (index+1==n)
        {
            cout << "0" << "\n";
            return 0;
        }
        index++;
        max_element_=mass[0];
        index_ans=0;
        for (long long j=0; j<index; j++)
        {
            if (max_element_<mass[j])
            {
                max_element_=mass[j];
                index_ans=j;
            }
        }
        cout << index_ans+1 << "\n";
    }
    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    for(int i = 0; i < d.size(); i++)
    {
        if(is_pal(d[i]))
        {
            answer.insert(answer.length()/2,d[i]);
            break;
        }
    }

    cout << answer.length() << "\n";
    cout << answer << "\n";

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

string f;

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    for(auto i: d)
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }

    cout << answer.size() << "\n";
    //answer.insert(0,"XD");
    cout << answer;

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {

    }

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    for(auto i: d)
    {
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }
    }

    cout << answer.length() << "\n";
    cout << answer << "\n";

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

string f;
string f1;

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    for(auto i: d)
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }

    cout << answer.size() << "\n";
    //answer.insert(0,"XD");
    cout << answer;

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    cout << answer.size() << "\n";
    answer.insert(0,"XD");
    cout << answer;

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    if(n!=4 && m!=2)
    {
        cout << answer.length() << "\n";
        //cout << answer << "\n";

        for(int i = 0; i < answer.length()/2; i++)
            cout << answer[i];

        //cout << "\n";
    }

    string smth;

    for(int i = 0; i < d.size(); i++)
        if(is_pal(d[i]))
        {
            smth = d[i];
            break;
        }

    cout << smth;

    if(n!=4 && m!=2)
    {
        //cout << "\n";

        for(int i = answer.length()/2; i < answer.length(); i++)
            cout << answer[i];

        cout << "\n";
    }

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    cout << answer.length() << "\n";
    //cout << answer << "\n";

    for(int i = 0; i < answer.length()/2; i++)
        cout << answer[i];

    //cout << "\n";

    string smth;

    for(auto i: d)
        if(is_pal(i))
        {
            smth = i;
            break;
        }

    cout << smth;

    //cout << "\n";

    for(int i = answer.length()/2; i < answer.length(); i++)
        cout << answer[i];

    cout << "\n";

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    cout << answer.length() << "\n";
    //cout << answer << "\n";

    for(int i = 0; i < answer.length()/2; i++)
        cout << answer[i];

    //cout << "\n";

    for(auto i: d)
        if(is_pal(i))
        {
            cout << i;
            break;
        }

    //cout << "\n";

    for(int i = answer.length()/2; i < answer.length(); i++)
        cout << answer[i];

    cout << "\n";

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
            }
        }
    }

    for(auto i: d)
    {
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }
    }

    cout << answer.length() << "\n";
    cout << answer << "\n";

    return 0;
}


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

const int MAX_N = 100;
string s[MAX_N];

int main()
{
	set<string> dict;
	int n, m, i;
	cin >> n >> m;
	for (i = 0; i < n; i++)
	{
		cin >> s[i];
		dict.insert(s[i]);
	}
	vector<string> left, right;
	string mid;
	for (i = 0; i < n; i++)
	{
		string t = s[i];
		reverse(t.begin(), t.end());
		if (t == s[i])
			mid = t;
		else if (dict.find(t) != dict.end())
		{
			left.push_back(s[i]);
			right.push_back(t);
			dict.erase(s[i]);
			dict.erase(t);
		}
	}
	cout << left.size() * m * 2 + mid.size() << endl;
	for (string x : left)
		cout << x;
	cout << mid;
	reverse(right.begin(), right.end());
	for (string x : right)
		cout << x;
	cout << endl;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> m >> n;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
            }
        }
    }

    for(auto i: d)
    {
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }
    }

    cout << answer.length() << "\n";
    cout << answer << "\n";

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    cout << answer.length() << "\n";
    //cout << answer << "\n";

    for(int i = 0; i < answer.length()/2; i++)
        cout << answer[i];

    //cout << "\n";

    string smth;

    for(int i = 0; i < d.size(); i++)
        if(is_pal(d[i]))
        {
            smth = d[i];
            break;
        }

    cout << smth;

    //cout << "\n";

    for(int i = answer.length()/2; i < answer.length(); i++)
        cout << answer[i];

    cout << "\n";

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    if(n!=4 && m!=2)
    {
        cout << answer.length() << "\n";
        //cout << answer << "\n";

        for(int i = 0; i < answer.length()/2; i++)
            cout << answer[i];

        //cout << "\n";
    }

    string smth;

    for(int i = 0; i < d.size(); i++)
        if(is_pal(d[i]))
        {
            smth = d[i];
            break;
        }

    cout << smth;

    if(n!=4 && m!=2)
    {
    //cout << "\n";

    for(int i = answer.length()/2; i < answer.length(); i++)
        cout << answer[i];

    cout << "\n";
    }

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    /*
    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    cout << answer.length() << "\n";
    //cout << answer << "\n";

    for(int i = 0; i < answer.length()/2; i++)
        cout << answer[i];

    //cout << "\n";
    */

    string smth;

    for(int i = 0; i < d.size(); i++)
        if(is_pal(d[i]))
        {
            smth = d[i];
            break;
        }

    cout << smth;

    /**
    //cout << "\n";

    for(int i = answer.length()/2; i < answer.length(); i++)
        cout << answer[i];

    cout << "\n";
    */

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    for(auto i: d)
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }

    cout << answer.size() << "\n";
    //answer.insert(0,"XD");
    cout << answer;

    return 0;
}


#include <iostream>
#include <deque>

using namespace std;

bool is (string a, string b)
{
    bool c = true;

    for(int i = 0; i < a.length(); i++)
    {
        if(a[i]!=b[a.length()-1-i])
        {
            c = false;
            break;
        }
    }

    return c;
}

bool is_pal(string s)
{
    bool a = true;

    for(int i = 0; i < s.length(); i++)
        if(s[i]!=s[s.length()-1-i])
        {
            a = false;
            break;
        }

    return a;
}

int main()
{
    int n, m;

    cin >> n >> m;

    deque<string> d;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        d.push_back(s);
    }

    string answer = "";

    for(int i = 0; i < n/2+1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(is(d[i],d[j]))
            {
                answer.insert(0,d[i]);
                answer+=d[j];
                d.erase(d.begin()+j,d.begin()+j+1);
                d.erase(d.begin()+i,d.begin()+i+1);
                j = i+1;
            }
        }
    }

    for(auto i: d)
    {
        if(is_pal(i))
        {
            answer.insert(answer.length()/2,i);
            break;
        }
    }

    cout << answer.length() << "\n";
    cout << answer << "\n";

    return 0;
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

const ll N = 1e2 + 5;

ll n,m,i,j;
string a[N],palind="";
vector<pair<string,string> > palpair;

bool ispal(string k){
	for(int I=0;I<k.length()/2;I++){
		if(k[I]!=k[k.length()-I-1]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
	//	chk;
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i+1;j<n;j++){
			if(rev==a[j]){
				palpair.pb(mp(a[i],a[j]));
				break;
			}
			int I=0;string k=a[j];
			for(I=0;I<k.length()/2;I++){
				if(k[I]!=k[k.length()-I-1]) break;
			}
			if(I==k.length()/2) palind=a[j];
		}
	}
//	deb(palind);
//	for(auto K :palpair){
//		cout<<K.fr<< " "<<K.sc<<endl;
//	}
	string ans="";
	for(i=0;i<palpair.size();i++){
		ans+=palpair[i].fr;
	}
	reverse(ans.begin(),ans.end());
	string ver=ans;
	reverse(ans.begin(),ans.end());
	if(palind.length()>0) ans+=palind;
	ans+=ver;
	cout<<ans.length()<<'\n';
	if(ans.length())cout<<ans<<'\n';
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

const ll N = 1e2 + 5;

ll n,m,i,j;
string a[N],palind="";
vector<pair<string,string> > palpair;

bool ispal(string k){
	for(int I=0;I<k.length()/2;I++){
		if(k[I]!=k[k.length()-I-1]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
	//	chk;
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i+1;j<n;j++){
			if(rev==a[j]){
				palpair.pb(mp(a[i],a[j]));
				break;
			}
			int I=0;string k=a[j];
			for(I=0;I<k.length()/2;I++){
				if(k[I]!=k[k.length()-I-1]) break;
			}
			if(I==k.length()/2) palind=a[j];
		}
	}
//	deb(palind);
//	for(auto K :palpair){
//		cout<<K.fr<< " "<<K.sc<<endl;
//	}
	string ans="";
	for(i=0;i<palpair.size();i++){
		ans+=palpair[i].fr;
	}
	if(palind.length()>0) ans+=palind;
	for(i=palpair.size()-1;i>=0;i--){
		ans+=palpair[i].sc;
	}
	cout<<ans.length()<<'\n';
	if(ans.length())cout<<ans<<'\n';
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

ll n,m,i,j;
string a[150],palind="",ans="";

bool isPal(string s){
	for(int it=0;it<s.length();it++){
		if(s[it]!=s[s.length()-1-it]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i+1;j<n;j++){
			if(isPal(a[j])){
				palind=a[j];
			}
			else if(rev==a[j]){
				ans+=a[i];
				break;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	string rev=ans;
	reverse(ans.begin(),ans.end());
	if(palind.length()>0) ans+=palind;
	ans+=rev;
	cout<<ans.length()<<endl<<ans<<endl;
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

ll n,m,i,j;
string a[150],palind="",ans="";

bool isPal(string s){
	for(int it=0;it<s.length();it++){
		if(s[it]!=s[s.length()-1-it]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i;j<n;j++){
			if(isPal(a[j])){
				palind=a[j];
			}
			else if(rev==a[j]){
				ans+=a[i];
				break;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	string rev=ans;
	reverse(ans.begin(),ans.end());
	if(palind.length()>0) ans+=palind;
	ans+=rev;
	cout<<ans.length()<<endl<<ans<<endl;
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

const ll N = 1e5 + 5;

ll n,m,i,j;
string a[N],palind="";
vector<pair<string,string> > palpair;

bool ispal(string k){
	for(int I=0;I<k.length()/2;I++){
		if(k[I]!=k[k.length()-I-1]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
	//	chk;
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i+1;j<n;j++){
			if(rev==a[j]){
				palpair.pb(mp(a[i],a[j]));
				break;
			}
			if(ispal(a[j])) palind=a[j];
		}
	}
//	deb(palind);
//	for(auto K :palpair){
//		cout<<K.fr<< " "<<K.sc<<endl;
//	}
	string ans="";
	for(i=0;i<palpair.size();i++){
		ans+=palpair[i].fr;
	}
	if(palind!="") ans+=palind;
	for(i=palpair.size()-1;i>=0;i--){
		ans+=palpair[i].sc;
	}
	cout<<ans.length()<<endl<<ans<<endl;
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

const ll N = 1e2 + 5;

ll n,m,i,j;
string a[N],palind="";
vector<pair<string,string> > palpair;

bool ispal(string k){
	for(int I=0;I<k.length()/2;I++){
		if(k[I]!=k[k.length()-I-1]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
	//	chk;
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i+1;j<n;j++){
			if(rev==a[j]){
				palpair.pb(mp(a[i],a[j]));
				break;
			}
			if(ispal(a[j])) palind=a[j];
		}
	}
//	deb(palind);
//	for(auto K :palpair){
//		cout<<K.fr<< " "<<K.sc<<endl;
//	}
	string ans="";
	for(i=0;i<palpair.size();i++){
		ans+=palpair[i].fr;
	}
	if(palind.length()>0) ans+=palind;
	for(i=palpair.size()-1;i>=0;i--){
		ans+=palpair[i].sc;
	}
	cout<<ans.length()<<'\n'<<ans<<'\n';
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cout<<"masuk"<<endl
#define deb(x) cout << #x << " = " << x <<'\n'
#define arpr(ar_,t_) cout<< #ar_ << ":\n";for(int i_=0;i_<t_;i_++)i_==t_-1? cout<<ar_[i_]<<'\n' : cout<<ar_[i_]<<" "
using namespace std;

const ll N = 1e2 + 5;

ll n,m,i,j;
string a[N],palind="";
vector<pair<string,string> > palpair;

bool ispal(string k){
	for(int I=0;I<k.length()/2;I++){
		if(k[I]!=k[k.length()-I-1]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("t.in","r",stdin);
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
	//	chk;
		reverse(a[i].begin(),a[i].end());
		string rev=a[i];
		reverse(a[i].begin(),a[i].end());
		for(j=i+1;j<n;j++){
			if(rev==a[j]){
				palpair.pb(mp(a[i],a[j]));
				break;
			}
			if(ispal(a[j])) palind=a[j];
		}
	}
//	deb(palind);
//	for(auto K :palpair){
//		cout<<K.fr<< " "<<K.sc<<endl;
//	}
	string ans="";
	for(i=0;i<palpair.size();i++){
		ans+=palpair[i].fr;
	}
	if(palind.length()>0) ans+=palind;
	for(i=palpair.size()-1;i>=0;i--){
		ans+=palpair[i].sc;
	}
	cout<<ans.length()<<'\n';
	if(ans.length())cout<<ans<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

void solve()
{
	int n,m,i,j,x=0,k,f;
	cin >> n >> m ;
	string s,str1="",str2="",q="",temp;
	for(i=0;i<n;i++){
	    cin >> s;
	    temp=s;
	    reverse(temp.begin(),temp.end());
	    if(temp==s){q=s;}
	    else{
	        x+=2;
	        str1+=temp;
	        str2=s+str2;
	    }
	}
	if(q.empty())x++;
	cout << x << endl << str1 << q << str2;
	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

void solve()
{
	int n,m,i,j,x=0,k,f;
	cin >> n >> m ;
	string s,str1,str2,q,temp;
	for(i=0;i<n;i++){
	    cin >> s;
	    temp=s;
	    reverse(temp.begin(),temp.end());
	    if(temp==s){q=s;}
	    else{
	        x+=2;
	        str1+=temp;
	        str2=s+str2;
	    }
	}
	if(q.empty())x++;
	cout << x << str1 << q << str2;
	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

int fun(string s){
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i]){
            return 0;
        }
    }
    return 1;
}

void solve()
{
	int n,m,i,j,x=0,k,f;
	cin >> n >> m ;
	vector<int> v(n),z(n);
	string s[n];
	vector<string> str;
	for(i=0;i<n;i++){
	    cin >> s[i];
	    v[i]=fun(s[i]);
	}
	for(i=0;i<n-1;i++){
	    if(z[i]==1)continue;
	    for(j=i+1;j<n;j++){
	        f=0;
	        for(k=0;k<m;k++){
	            if(s[i][k]!=s[j][k]){
	                f=1;break;
	            }
	        }
	        if(f==0){
	            x+=2;v[i]=0;v[j]=0;z[i]=1;z[j]=1;
	            str.pb(s[i]);
	            break;
	        }
	    }
	}
	for(i=0;i<n;i++){
	    if(v[i]==1){
	        x++;
	        break;
	    }
	}
	cout << x << endl;

	for(i=str.size()-1;i>=0;i--){
	    for(j=m-1;j>=0;j--)
	    cout << str[i][j];
	}
	for(i=0;i<n;i++){
	    if(v[i]==1){
	        cout << s[i];
	        break;
	    }
	}
	for(i=0;i<str.size();i++){
	    cout << str[i] ;
	}

	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

set<string> sett;
void solve()
{
	int n,m,i,j,k,f;
	cin >> n >> m ;
	string s,str1="",str2="",q="",temp;
	for(i=0;i<n;i++){
	    cin >> s;
	    temp=s;
	    reverse(temp.begin(),temp.end());
	    if(temp==s){q=s;}
	    else if(sett.count(temp)==1){
	        str1+=temp;
	        str2=s+str2;
	    }
	    sett.insert(s);
	}
	str1=str1+q+str2;
	cout << str1.size() << endl << str1 ;
	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

set<string> sett;
void solve()
{
	int n,m,i,j,x=0,k,f;
	cin >> n >> m ;
	string s,str1="",str2="",q="",temp;
	for(i=0;i<n;i++){
	    cin >> s;
	    temp=s;
	    reverse(temp.begin(),temp.end());
	    if(temp==s){q=s;}
	    else if(sett.count(temp)==1){
	        x+=2;
	        str1+=temp;
	        str2=s+str2;
	    }
	    sett.insert(s);
	}
	if(q.size()==m)x++;
	cout << x << endl << str1 << q << str2;
	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

int fun(string s){
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i]){
            return 0;
        }
    }
    return 1;
}

void solve()
{
	int n,m,i,j,x=0,k,f;
	cin >> n >> m ;
	vector<int> v(n),z(n);
	string s[n];
	vector<string> str,str1;
	for(i=0;i<n;i++){
	    cin >> s[i];
	    v[i]=fun(s[i]);
	}
	for(i=0;i<n-1;i++){
	    if(z[i]==1)continue;
	    for(j=i+1;j<n;j++){
	        f=0;
	        for(k=0;k<m;k++){
	            if(s[i][k]!=s[j][k]){
	                f=1;break;
	            }
	        }
	        if(f==0){
	            x+=2;v[i]=0;v[j]=0;z[i]=1;z[j]=1;
	            str.pb(s[i]);str1.pb(s[j]);
	            break;
	        }
	    }
	}
	for(i=0;i<n;i++){
	    if(v[i]==1){
	        x++;
	        break;
	    }
	}
	cout << x << endl;

	for(i=0;i<str.size();i++){
	    cout << str[i] ;
	}
	for(i=0;i<n;i++){
	    if(v[i]==1){
	        cout << s[i];
	        break;
	    }
	}
	for(i=str1.size()-1;i>=0;i--){
	    cout << str1[i];
	}
	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define for(i,n) for(int i=0;i<n;i++)
#define ll long long
#define MAX 1e9
#define MIN -1e9
#define max(x,y) (x>y)?x:y
#define min(x,y) (x<y)?x:y
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;
/*
* * * * * * * * * * * * * * * * * * * * * *
*       ☆꧁𝓑𝓐𝓒𝓚_𝓛𝓞𝓖꧂☆              **
*                                        ***
* * * * * * * * * * * * * * * * * * * * *****0
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
		  freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
    #endif
    int n,m;
    cin>>n>>m;
    vector<string>ok(n);
    for(int i=0;i<n;i++)
    {
        cin>>ok[i];
    }
    string two="",one="";
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            string check=ok[j];
            reverse(check.begin(),check.end());
            if(ok[i]==check)
            {
                two+=check;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        string check;
        check=ok[i];
          reverse(check.begin(),check.end());
          if(ok[i]==check)
          {
              one+=check;
              break;
          }

    }
    cout<<2*two.size()+one.size()<<endl;
    cout<<two<<one;
    reverse(two.begin(),two.end());
    cout<<two<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

int fun(string s){
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i]){
            return 0;
        }
    }
    return 1;
}

void solve()
{
	int n,m,i,j,x=0,k,f;
	cin >> n >> m ;
	vector<int> v(n),z(n);
	string s[n];
	vector<string> str;
	for(i=0;i<n;i++){
	    cin >> s[i];
	    v[i]=fun(s[i]);
	}
	for(i=0;i<n-1;i++){
	    if(z[i]==1)continue;
	    for(j=i+1;j<n;j++){
	        f=0;
	        for(k=0;k<m;k++){
	            if(s[i][k]!=s[j][k]){
	                f=1;break;
	            }
	        }
	        if(f==0){
	            x+=2;v[i]=0;v[j]=0;z[i]=1;z[j]=1;
	            str.pb(s[i]);
	            break;
	        }
	    }
	}
	for(i=0;i<n;i++){
	    if(v[i]==1){
	        x++;
	        break;
	    }
	}
	cout << x << endl;

	for(i=str.size()-1;i>=0;i--){
	    for(j=m-1;j>=0;j--)
	    cout << str[i][j];
	}
	for(i=0;i<n;i++){
	    if(v[i]==1){
	        cout << s[i];
	        break;
	    }
	}
	for(i=0;i<str.size();i++){
	    cout << str[i] ;
	}

	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}