I uploaded questions and requirements on the attachment. I also uploaded some examples for you to understand more clearly.
Please contact me if you have any questions.