You are given three distinct items and their respective maximum quantities. Additionally, an integer n is provided. Your task is to generate all possible sequences of length n where each element in the sequence is one of the three items, and the total number of times each item appears in the sequence does not exceed its given quantity. The sequences must be printed in lexicographical order based on the order of the items provided. Each sequence should be printed on a new line.
Input: Items: A B C
Quantities: 2 1 1
n: 2
Output: AA
AB
AC
BA
BC
CA
CB
Explanation: The items A, B, C have maximum allowed counts 2, 1, 1. For n=2, all valid sequences where no item exceeds its count are listed in lex order based on item order A<B<C.
Input: Items: A B C
Quantities: 1 1 1
n: 2
Output: AB
AC
BA
BC
CA
CB
Explanation: With each item allowed at most once, all sequences of length 2 with distinct items are generated in lex order.
Input: Items: A B C
Quantities: 0 2 2
n: 2
Output: BB
BC
CB
CC
Explanation: Item A has quantity 0, so only B and C are used. Sequences are formed with at most 2 B and 2 C, in lex order B<C.