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

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

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

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

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

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

f.o = d
d.u = f
k.o = d
assert k.o.u.o.txt == "d"