r = import("R.csv"); for i in r { for j in r { for k in r { if i[1] == j[0] and j[1] == k[0] { out.add(i[0], k[1]); } } } }