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

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

a = A("a")
d = B("d")
c = B("c")
f = A("f")

a.o = c
d.v = f
d.x = a
c.v = f
c.x = a
f.o = d
assert f.o.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

a = A("a")
d = B("d")
c = B("c")
f = A("f")

a.o = c
d.v = f
d.x = a
c.v = f
c.x = a
f.o = d
assert f.o.x.o.x.txt == "a"