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

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

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

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

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

m = A("m")
d = B("d")
c = C("c")
b = D("b")
h = E("h")
k = A("k")

m.x = k
d.s = b
d.r = c
c.q = b
c.r = b
b.r = h
b.o = h
h.r = m
k.x = m
assert b.o.r.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

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

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

m = A("m")
d = B("d")
c = C("c")
b = D("b")
h = E("h")
k = A("k")

m.x = k
d.s = b
d.r = c
c.q = b
c.r = b
b.r = h
b.o = h
h.r = m
k.x = m
assert b.o.r.x.x.x.x.txt == "m"