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

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

f = A("f")
k = B("k")
j = B("j")
m = A("m")
g = B("g")

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

f = A("f")
k = B("k")
j = B("j")
m = A("m")
g = B("g")

f.u = m
k.y = j
k.r = m
j.y = g
j.r = m
m.u = f
g.y = k
g.r = f
assert f.u.u.u.txt == "m"