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

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

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

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

m.o = l
h.w = m
l.x = g
g.o = l
assert l.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

m.o = l
h.w = m
l.x = g
g.o = l
assert l.x.o.x.txt == "g"