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

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

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

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

c = A("c")
a = B("a")
n = C("n")
d = D("d")
m = C("m")
k = C("k")

c.y = d
a.t = d
a.s = d
a.w = d
a.o = c
n.y = c
d.t = a
m.y = c
k.y = c
assert m.y.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

c = A("c")
a = B("a")
n = C("n")
d = D("d")
m = C("m")
k = C("k")

c.y = d
a.t = d
a.s = d
a.w = d
a.o = c
n.y = c
d.t = a
m.y = c
k.y = c
assert m.y.y.t.txt == "a"