Query Distance

q1 and qn are two queries.
Let f1, ..., fn-1 be n-1 transformations such that
f1(q1) = q2, f2(q2) = q3, ..., fn-1(qn-1) = qn.
The distance d(q1,qn) between two queries
q1 and qn is defined as: where wj is the weight for transformation step fj