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

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

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

j = A("j")
l = B("l")
k = C("k")
i = C("i")
e = C("e")
g = C("g")
m = C("m")
b = A("b")
c = B("c")

j.x = m
l.s = j
l.v = c
k.q = i
i.q = e
e.q = g
g.q = i
m.q = k
b.x = g
c.s = b
c.v = l
assert k.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

j = A("j")
l = B("l")
k = C("k")
i = C("i")
e = C("e")
g = C("g")
m = C("m")
b = A("b")
c = B("c")

j.x = m
l.s = j
l.v = c
k.q = i
i.q = e
e.q = g
g.q = i
m.q = k
b.x = g
c.s = b
c.v = l
assert k.q.q.q.q.q.q.txt == "g"