s = import("S.csv"); t = import("T.csv"); for sr in s { for tr in t { if sr[0] == sr[1] and tr[1] == tr[2] { out.add(sr[2], tr[0]) }; } }