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

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

f = A("f")
j = B("j")
c = B("c")
d = A("d")
m = B("m")

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

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

f = A("f")
j = B("j")
c = B("c")
d = A("d")
m = B("m")

f.o = d
j.v = d
c.v = f
d.o = f
m.v = d
assert c.v.o.o.o.o.txt == "f"