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

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

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

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

h = A("h")
g = B("g")
d = C("d")
l = D("l")

h.w = d
g.p = l
d.q = g
l.t = g
l.s = d
l.x = d
assert d.q.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
d = C("d")
l = D("l")

h.w = d
g.p = l
d.q = g
l.t = g
l.s = d
l.x = d
assert d.q.p.s.txt == "d"