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

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

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

d = A("d")
j = B("j")
k = C("k")
n = A("n")
l = A("l")
e = C("e")
b = C("b")
a = B("a")

d.z = n
j.q = a
j.v = k
j.z = n
k.s = j
n.z = d
l.z = d
e.s = j
b.s = a
a.q = j
a.v = b
a.z = l
assert j.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
k = C("k")
n = A("n")
l = A("l")
e = C("e")
b = C("b")
a = B("a")

d.z = n
j.q = a
j.v = k
j.z = n
k.s = j
n.z = d
l.z = d
e.s = j
b.s = a
a.q = j
a.v = b
a.z = l
assert j.z.z.z.z.txt == "d"