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

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

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

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

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

m.o = a
m.y = a
f.s = k
f.z = k
f.v = a
f.x = m
a.u = f
a.z = m
a.x = d
i.r = m
i.u = d
k.s = f
k.z = f
k.v = a
k.x = m
d.r = m
d.u = i
assert k.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: C = None
        self.txt = txt

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

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

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

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

m.o = a
m.y = a
f.s = k
f.z = k
f.v = a
f.x = m
a.u = f
a.z = m
a.x = d
i.r = m
i.u = d
k.s = f
k.z = f
k.v = a
k.x = m
d.r = m
d.u = i
assert k.x.o.x.txt == "d"