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

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

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

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

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

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

b.w = i
b.v = g
m.t = i
f.w = a
f.v = g
h.t = i
g.w = m
g.v = f
i.t = m
a.t = m
assert i.t.t.t.t.t.txt == "m"