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

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

n = A("n")
f = B("f")
d = A("d")

n.r = d
f.u = n
d.r = n
assert d.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

n = A("n")
f = B("f")
d = A("d")

n.r = d
f.u = n
d.r = n
assert d.r.r.r.txt == "n"