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

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

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

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

b = A("b")
a = B("a")
k = C("k")
i = D("i")
f = B("f")
m = C("m")
d = A("d")

b.y = a
b.o = i
a.q = f
a.s = f
a.p = f
k.w = m
k.t = d
k.o = f
i.z = m
i.t = d
i.o = a
f.q = a
f.s = a
f.p = a
m.w = k
m.t = b
m.o = a
d.y = a
d.o = i
assert m.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: D = None
        self.txt = txt

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

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

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

b = A("b")
a = B("a")
k = C("k")
i = D("i")
f = B("f")
m = C("m")
d = A("d")

b.y = a
b.o = i
a.q = f
a.s = f
a.p = f
k.w = m
k.t = d
k.o = f
i.z = m
i.t = d
i.o = a
f.q = a
f.s = a
f.p = a
m.w = k
m.t = b
m.o = a
d.y = a
d.o = i
assert m.w.w.w.txt == "k"