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

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

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

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

d = A("d")
h = B("h")
n = C("n")
i = D("i")
c = B("c")
a = D("a")

d.p = n
d.o = i
d.s = a
h.w = d
n.x = d
n.z = d
n.p = h
n.u = h
i.u = d
c.w = d
a.u = d
assert d.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.o: D = None
        self.s: D = None
        self.txt = txt

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

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

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

d = A("d")
h = B("h")
n = C("n")
i = D("i")
c = B("c")
a = D("a")

d.p = n
d.o = i
d.s = a
h.w = d
n.x = d
n.z = d
n.p = h
n.u = h
i.u = d
c.w = d
a.u = d
assert d.s.u.s.txt == "a"