#!/usr/bin/perl -w

$infile1=$ARGV[0];
$infile2=$ARGV[1];
$infile3=$ARGV[2];

open IN1,$infile1;
while (<IN1>)
{
	chomp;
	($cle,$valeur)=split(/\t/,$_);
	$hash1{$cle}=$valeur;
}
close IN1;

open IN2,$infile2;
while (<IN2>)
{
	chomp;
	($cle,$valeur)=split(/\t/,$_);
	$hash2{$cle}=$valeur;
}
close IN2;

open IN3,$infile3;
while (<IN3>)
{
	chomp;
	($cle,$valeur)=split(/\t/,$_);
	$hash3{$cle}=$valeur;
}
close IN3;

foreach $cle (keys %hash1)
{
	if ($hash2{$hash1{$cle}} && $hash3{$hash2{$hash1{$cle}}})
	{
		if ($hash3{$hash2{$hash1{$cle}}} eq $cle)
		{
			print "$cle\t$hash1{$cle}\n";
		}
	}
}
