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

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

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

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

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

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

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