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

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

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

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

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

n = A("n")
k = B("k")
j = C("j")
m = D("m")
g = E("g")
c = A("c")

n.x = j
n.v = j
k.q = m
k.x = c
k.z = c
j.p = c
m.r = k
m.z = k
g.q = c
g.r = c
g.z = j
c.x = j
c.v = j
assert k.x.x.p.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.v: C = None
        self.txt = txt

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

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

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

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

n = A("n")
k = B("k")
j = C("j")
m = D("m")
g = E("g")
c = A("c")

n.x = j
n.v = j
k.q = m
k.x = c
k.z = c
j.p = c
m.r = k
m.z = k
g.q = c
g.r = c
g.z = j
c.x = j
c.v = j
assert k.x.x.p.x.p.x.txt == "j"