p(a, b). p(b, c). p(X, Y) :- p(X, Z), p(Z, Y).