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

class B:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: C = None
        self.t: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.y: D = None
        self.txt = txt

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

m = A("m")
g = B("g")
h = C("h")
f = D("f")

m.o = f
g.u = m
g.s = h
g.t = f
h.z = g
h.y = f
f.r = g
assert f.r.s.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: C = None
        self.t: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.y: D = None
        self.txt = txt

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

m = A("m")
g = B("g")
h = C("h")
f = D("f")

m.o = f
g.u = m
g.s = h
g.t = f
h.z = g
h.y = f
f.r = g
assert f.r.s.y.r.txt == "g"