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

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

i = A("i")
g = B("g")
f = A("f")
c = B("c")
a = B("a")

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

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

i = A("i")
g = B("g")
f = A("f")
c = B("c")
a = B("a")

i.s = f
i.v = g
g.o = i
f.s = i
f.v = c
c.o = f
a.o = f
assert i.s.v.o.s.s.txt == "f"