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

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

h = A("h")
b = B("b")
i = A("i")
l = B("l")
g = A("g")

h.z = g
b.z = l
b.o = l
i.z = h
l.z = b
l.o = b
g.z = i
assert i.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.z: B = None
        self.o: B = None
        self.txt = txt

h = A("h")
b = B("b")
i = A("i")
l = B("l")
g = A("g")

h.z = g
b.z = l
b.o = l
i.z = h
l.z = b
l.o = b
g.z = i
assert i.z.z.z.z.z.txt == "g"