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

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

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

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

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

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

i.y = g
n.t = b
g.y = i
m.y = i
h.t = e
a.y = m
c.y = g
e.t = b
b.t = e
j.t = b
assert m.y.y.y.y.y.y.y.y.y.txt == "i"