#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
void PrintArrays (const std::vector<std::vector<std::string>> items)
{
    vector<int> indices;
    int n = items.size();
        indices.resize(items.size(),0);
        
        while (true) //Iterate until we've used all of the last array of items
        {
                //Print
                for (int i = 0; i < n; ++i)
                {
                        cout << items[i][indices[i]] << " ";
                }
                cout << endl;
                
                //Update to the next indice
                for (int i = n - 1; i >= 0; --i)
                {
                        indices[i] = (indices[i] + 1) % items[i].size();
                        if (indices[i] != 0)
                        {
                             break;
                        }
                        else if (indices[i] == 0 && i == 0)
                        {
                            return; //Escape.
                        }
                }
        }
        
}
 
int main() {
        
    vector<vector<string>> lists;
    
    
    lists.resize(4);
    lists[0].push_back("AA");
    lists[0].push_back("BB");
    lists[1].push_back("CC");
    lists[2].push_back("DD");
    lists[2].push_back("EE");
    lists[2].push_back("FF");
    lists[3].push_back("GG");
    
    PrintArrays(lists);
    
        return 0;
}