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.txt = txt

a = A("a")
j = B("j")
b = B("b")
l = A("l")
k = B("k")
f = B("f")
m = A("m")
d = B("d")

a.s = b
j.o = d
b.o = d
l.s = k
k.o = j
f.o = j
m.s = k
d.o = b
assert m.s.o.o.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.txt = txt

a = A("a")
j = B("j")
b = B("b")
l = A("l")
k = B("k")
f = B("f")
m = A("m")
d = B("d")

a.s = b
j.o = d
b.o = d
l.s = k
k.o = j
f.o = j
m.s = k
d.o = b
assert m.s.o.o.o.txt == "b"