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

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

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

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

h = A("h")
a = B("a")
k = C("k")
d = D("d")

h.w = a
h.x = a
a.v = h
a.y = h
k.w = a
k.q = a
k.o = d
d.s = h
assert d.s.w.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.x: B = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
k = C("k")
d = D("d")

h.w = a
h.x = a
a.v = h
a.y = h
k.w = a
k.q = a
k.o = d
d.s = h
assert d.s.w.y.w.txt == "a"