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

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

f = A("f")
c = B("c")
g = B("g")
m = A("m")
d = B("d")
l = B("l")

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

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

f = A("f")
c = B("c")
g = B("g")
m = A("m")
d = B("d")
l = B("l")

f.s = d
c.o = d
c.v = f
g.o = l
g.v = f
m.s = c
d.o = g
d.v = f
l.o = g
l.v = m
assert f.s.v.s.o.txt == "g"