#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 64

struct node{
    long long int money; /*かかった費用*/
    long long int n;/*現在のn*/
    long long int value;/*評価値 */
    struct node *next;
};

struct node getNext(struct node *first){
    long long int min_value;
    struct node *c = first;
    struct node *previous_c = first;
    if(first = NULL) return NULL;
    while(c != NULL){
        if (c->value < min_value) min_value = c->value;
        c = c->next;
    }
    
    while(1){
        if(c->value == min_value){
            previous_c->next = c->next;
            return c;
        }
        previous_c = c;
        c = c->next;
    }
}

int main(void){
    char input[MAX];
    int t = 0; /*入力T(問題文中で定義）*/
    int i;/*loop variable*/
    int a=0,b=0,c=0,d=0;
    long long int n=0, answer=0;
    struct node *first;

    fgets(input,MAX,stdin);
    t = atoi(input);
    for(i=0;i<t;i++){
        fgets(input,MAX,stdin);
        n = atoll(strtok(input," "));
        a=atoi(strtok(NULL," "));
        b=atoi(strtok(NULL," "));
        c=atoi(strtok(NULL," "));
        d=atoi(strtok(NULL,"\n"));
        
        while((current = getNext(first))!=NULL){
            (struct node )malloc(struct node);
        }
        fprintf(stdout,"fail\n")
        /*あきらめた*/
    }
    return 0;
}