This problem has three challenges:
The first challenge is not very hard, so I encourage you to think about it for at least a little while. Don't worry about cycles at first.
One way to get started is to have your first version of label just print all the values, one per line, in an arbitrarily nested arrays of arrays, such as [10,[20,30],[40,[50,[60]]]] and [[[[[1]],2]],3].
If you have trouble with traversal, here's a hint.
The second two challenges are related—if we can find a way to produce and record labels for arrays and hashes, detecting a cycle amounts to seeing if an object already has a label. Think about using a hash whose keys are object id values (returned by the .object_id method) and whose values are labels like "a1" and "h2". Click here for more on this.