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

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

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

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

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

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

n.r = d
d.t = b
d.q = c
b.r = d
b.q = n
c.t = a
c.z = b
a.o = c
m.r = d
assert b.r.q.z.r.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

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

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

n.r = d
d.t = b
d.q = c
b.r = d
b.q = n
c.t = a
c.z = b
a.o = c
m.r = d
assert b.r.q.z.r.t.q.txt == "n"