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

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

j = A("j")
n = B("n")
b = A("b")
a = A("a")
m = A("m")
e = A("e")
i = B("i")

j.t = a
n.q = m
b.t = m
a.t = e
m.t = b
e.t = m
i.q = b
assert b.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

j = A("j")
n = B("n")
b = A("b")
a = A("a")
m = A("m")
e = A("e")
i = B("i")

j.t = a
n.q = m
b.t = m
a.t = e
m.t = b
e.t = m
i.q = b
assert b.t.t.t.t.t.txt == "m"