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

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

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

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

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

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

m.q = a
m.y = n
m.p = n
a.x = j
a.v = n
n.w = m
d.v = a
d.r = n
j.s = d
assert j.s.v.x.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: C = None
        self.p: C = None
        self.txt = txt

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

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

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

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

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

m.q = a
m.y = n
m.p = n
a.x = j
a.v = n
n.w = m
d.v = a
d.r = n
j.s = d
assert j.s.v.x.s.r.txt == "n"