class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

i = A("i")
f = B("f")
c = A("c")
d = B("d")
n = B("n")
a = B("a")
b = B("b")

i.z = c
f.o = n
c.z = i
d.o = a
n.o = d
a.o = b
b.o = d
assert c.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

i = A("i")
f = B("f")
c = A("c")
d = B("d")
n = B("n")
a = B("a")
b = B("b")

i.z = c
f.o = n
c.z = i
d.o = a
n.o = d
a.o = b
b.o = d
assert c.z.z.z.z.z.txt == "i"