  In this paper we study twisted traces of products of intertwining operators
for quantum affine algebras. They are interesting special functions, depending
on two weights lambda, mu, three scalar parameters q, omega, k, and spectral
parameters z_1,...,z_N, which may be regarded as q-analogs of conformal blocks
of the Wess-Zumino-Witten model on an elliptic curve. It is expected that in
the rank 1 case they essentially coincide with the elliptic hypergeometric
functions defined in math.QA/0110081. Our main result is that after a suitable
renormalization the traces satisfy four systems of difference equations -- the
Macdonald-Ruijsenaars equation, the q-Knizhnik-Zamolodchikov-Bernard equation,
and their dual versions. We also show that in the case when the twisting
automorphism is trivial, the trace functions are symmetric under the
permutation lambda <--> mu, k <--> omega. Thus, our results here generalize our
previous results, dealing with the case q = 1 and the finite dimensional case.
