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

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

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

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

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

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

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