class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.q: D = None
        self.r: C = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
h = C("h")
c = D("c")

g.w = c
g.q = c
g.r = h
n.y = h
n.w = c
h.t = c
c.s = n
c.w = h
c.r = h
c.y = h
assert h.t.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.q: D = None
        self.r: C = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
h = C("h")
c = D("c")

g.w = c
g.q = c
g.r = h
n.y = h
n.w = c
h.t = c
c.s = n
c.w = h
c.r = h
c.y = h
assert h.t.s.y.txt == "h"