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

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

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

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

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

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

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