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

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

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

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

b = A("b")
c = B("c")
h = C("h")
i = D("i")
k = B("k")

b.w = h
c.y = b
c.o = i
h.s = b
h.x = b
i.q = h
i.x = h
i.v = h
i.s = c
k.y = b
k.o = i
assert b.w.x.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

b = A("b")
c = B("c")
h = C("h")
i = D("i")
k = B("k")

b.w = h
c.y = b
c.o = i
h.s = b
h.x = b
i.q = h
i.x = h
i.v = h
i.s = c
k.y = b
k.o = i
assert b.w.x.w.s.w.txt == "h"