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

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

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

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

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

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

b.p = c
b.q = n
k.p = c
c.s = b
n.z = k
a.s = c
a.z = b
a.r = n
a.y = n
assert b.p.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: D = None
        self.txt = txt

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

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

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

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

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

b.p = c
b.q = n
k.p = c
c.s = b
n.z = k
a.s = c
a.z = b
a.r = n
a.y = n
assert b.p.s.q.txt == "n"