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

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

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

f.u = m
g.y = f
m.u = f
a.y = m
j.y = f
n.y = f
assert f.u.u.u.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.y: A = None
        self.txt = txt

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

f.u = m
g.y = f
m.u = f
a.y = m
j.y = f
n.y = f
assert f.u.u.u.u.u.u.txt == "f"