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

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

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

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

class E:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: B = None
        self.y: D = None
        self.p: B = None
        self.txt = txt

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

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

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

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

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

class E:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: B = None
        self.y: D = None
        self.p: B = None
        self.txt = txt

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

c.q = k
c.r = b
b.r = c
k.z = b
d.t = c
d.p = c
d.r = k
a.t = b
a.x = b
a.p = b
a.y = d
n.t = c
n.p = c
n.r = k
assert c.q.z.r.txt == "c"