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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.t: C = None
        self.txt = txt

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

l = A("l")
c = B("c")
g = C("g")
m = A("m")

l.o = m
c.p = g
c.t = g
g.z = l
m.o = l
assert c.t.z.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.t: C = None
        self.txt = txt

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

l = A("l")
c = B("c")
g = C("g")
m = A("m")

l.o = m
c.p = g
c.t = g
g.z = l
m.o = l
assert c.t.z.o.o.txt == "l"