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

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: C = None
        self.txt = txt

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

g = A("g")
m = B("m")
l = C("l")
b = C("b")
e = C("e")
d = B("d")

g.z = m
m.u = d
m.r = l
l.x = m
b.x = m
e.x = m
d.u = m
d.r = b
assert d.r.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: C = None
        self.txt = txt

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

g = A("g")
m = B("m")
l = C("l")
b = C("b")
e = C("e")
d = B("d")

g.z = m
m.u = d
m.r = l
l.x = m
b.x = m
e.x = m
d.u = m
d.r = b
assert d.r.x.r.x.txt == "m"