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

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

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

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

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

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

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

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

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

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

h.u = d
l.o = b
l.s = h
l.p = h
d.w = b
b.y = h
b.p = h
b.t = l
g.o = b
g.s = h
g.p = h
assert h.u.w.t.p.txt == "h"