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

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

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

e.q = j
n.r = m
m.q = k
d.r = e
g.r = m
a.r = e
j.q = k
k.q = e
assert m.q.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.r: A = None
        self.txt = txt

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

e.q = j
n.r = m
m.q = k
d.r = e
g.r = m
a.r = e
j.q = k
k.q = e
assert m.q.q.q.q.q.q.txt == "j"