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

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

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

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

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

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

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