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

class B:
    def __init__(self, txt: str):
        self.p: A = 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.w: B = None
        self.s: B = None
        self.txt = txt

j = A("j")
k = B("k")
g = C("g")
e = D("e")
h = C("h")

j.u = h
j.p = g
j.y = e
j.w = e
k.p = j
g.q = k
e.w = k
e.s = k
h.q = k
assert g.q.p.w.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.p: C = None
        self.y: D = None
        self.w: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = 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.w: B = None
        self.s: B = None
        self.txt = txt

j = A("j")
k = B("k")
g = C("g")
e = D("e")
h = C("h")

j.u = h
j.p = g
j.y = e
j.w = e
k.p = j
g.q = k
e.w = k
e.s = k
h.q = k
assert g.q.p.w.s.p.txt == "j"