
fn print_gene_pairs(genes: &Vec<String>) {
    for i in 0..(genes.len()-1) {
        for j in (i+1)..(genes.len()) {
            println!("{}\t{}", genes[i], genes[j]);
        }
    }
}

fn main() {
    let mut family_index: String = "".to_string();
    let mut family_genes: Vec<String> = Vec::new();
    for line in std::io::stdin().lines() {
        let line = line.unwrap();
        let mut parts = line.split("\t");
        let gene = parts.next().unwrap().to_string();
        let family = parts.next().unwrap().to_string();
        if family != family_index {
            family_index = family;
            if family_genes.len() > 1 {
                print_gene_pairs(&family_genes);
            }                    
            family_genes.clear();
        }
        if gene != "" {
            family_genes.push(gene);
        }
    }
    if family_genes.len() > 1 {
        print_gene_pairs(&family_genes);
    }
}
