#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 500010
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

int n, lg[MAX], ar[MAX];
long long sum[MAX], dp[MAX][18];

long long query(int i, int j){
    int k = lg[j - i];
    long long x = dp[i][k];
    long long y = dp[j - (1 << k) + 1][k];
    if (x > y) return x;
    else return y;
}

void SparseTable(){
    int i, l, d, len;
    for (l = 0; l < 18; l++){
        len = (1 << l);
        for (i = 0; (i + len) <= n; i++){
            if (!l) dp[i][l] = sum[i];
            else{
                d = 1 << (l - 1);
                dp[i][l] = dp[i + d][l - 1];
                if (dp[i][l - 1] > dp[i][l]) dp[i][l] = dp[i][l - 1];
            }
        }
    }
}

int main(){
    long long x, y;
    int t, i, j, low, high, mid, idx;

    lg[0] = lg[1] = 0;
    for (i = 2; i < MAX; i++) lg[i] = lg[i >> 1] + 1;

    scanf("%d", &t);
    while (t--){
        scanf("%d %lld", &n, &x);
        for (i = 0; i < n; i++){
            scanf("%d", &ar[i]);
            sum[i] = ar[i];
            if (i) sum[i] += sum[i - 1];
        }
        SparseTable();

        int res = MAX;
        for (i = 0; i < n; i++){
            y = 0;
            if (i) y = sum[i - 1];
            low = i, high = n - 1;

            if ((query(i, high) - x) >= y){
                while ((low + 1) < high){
                    mid = (low + high) >> 1;
                    if ((query(i, mid) - x) >= y) high = mid;
                    else low = mid;
                }

                if ((query(i, low) - x) >= y) idx = low + 1;
                else idx = high + 1;

                int r = idx - i;
                if (r < res) res = r;
            }
        }

        if (res == MAX) puts("-1");
        else printf("%d\n", res);
    }
    return 0;
}