Doing some resolutions ...
p(X) | p(f(Y)) | q(X,Y) ~p(f(a)) | ~p(Z) | ~q(c,d)
S = { p(a) | q(X), ~p(Y) | q(f(Y)), p(a) | ~q(T), ~p(A) | ~q(W) }