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

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

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

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

h = A("h")
j = B("j")
l = C("l")
a = D("a")

h.p = l
j.p = a
j.o = a
j.w = l
l.s = a
a.r = j
a.w = h
a.u = l
assert l.s.r.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
l = C("l")
a = D("a")

h.p = l
j.p = a
j.o = a
j.w = l
l.s = a
a.r = j
a.w = h
a.u = l
assert l.s.r.w.s.txt == "a"