Quark Script To Generate ID

Hi All,

I got one another requirement which I am describing below. I have quark document with a lot of text frames on the pages. I want to link X numbers of text frames of X pages and Y numbers of text frames of Y page. How can i do it. Please put some idea on it.

Thanks,
Rajeev