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

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.r: A = None
        self.x: A = None
        self.t: D = None
        self.u: E = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
f = C("f")
a = D("a")
m = E("m")

n.r = a
k.q = n
k.s = f
f.y = a
f.t = a
f.r = n
f.x = n
f.u = m
a.r = n
a.z = n
m.u = a
assert a.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.r: A = None
        self.x: A = None
        self.t: D = None
        self.u: E = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
f = C("f")
a = D("a")
m = E("m")

n.r = a
k.q = n
k.s = f
f.y = a
f.t = a
f.r = n
f.x = n
f.u = m
a.r = n
a.z = n
m.u = a
assert a.r.r.r.txt == "n"