start to make pairwise algorithm