Span program for non-binary functions