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

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

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

j.s = d
j.y = f
f.o = b
b.s = f
b.y = d
d.o = j
assert f.o.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.txt = txt

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

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

j.s = d
j.y = f
f.o = b
b.s = f
b.y = d
d.o = j
assert f.o.y.o.y.txt == "f"