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

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.t: A = None
        self.y: D = None
        self.q: D = None
        self.txt = txt

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

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

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

g.u = h
f.x = h
f.y = h
f.q = h
f.t = g
a.w = g
a.u = f
a.p = f
a.v = f
h.y = f
assert h.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.t: A = None
        self.y: D = None
        self.q: D = None
        self.txt = txt

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

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

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

g.u = h
f.x = h
f.y = h
f.q = h
f.t = g
a.w = g
a.u = f
a.p = f
a.v = f
h.y = f
assert h.y.y.y.txt == "f"