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

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

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

n.y = g
e.y = f
m.y = g
h.y = a
g.y = h
a.y = g
b.y = m
f.y = e
j.y = h
assert m.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.y: B = None
        self.txt = txt

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

n.y = g
e.y = f
m.y = g
h.y = a
g.y = h
a.y = g
b.y = m
f.y = e
j.y = h
assert m.y.y.y.txt == "a"