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

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

k = A("k")
j = B("j")
m = B("m")
g = A("g")
a = A("a")
b = A("b")
n = A("n")

k.q = a
j.y = m
j.p = a
m.y = j
m.p = a
g.q = k
a.q = b
b.q = k
n.q = g
assert j.p.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

k = A("k")
j = B("j")
m = B("m")
g = A("g")
a = A("a")
b = A("b")
n = A("n")

k.q = a
j.y = m
j.p = a
m.y = j
m.p = a
g.q = k
a.q = b
b.q = k
n.q = g
assert j.p.q.q.q.q.q.txt == "k"