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

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

m = A("m")
g = B("g")
i = A("i")
d = A("d")
f = A("f")
k = A("k")
j = B("j")

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

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

m = A("m")
g = B("g")
i = A("i")
d = A("d")
f = A("f")
k = A("k")
j = B("j")

m.o = i
g.s = d
i.o = k
d.o = m
f.o = d
k.o = m
j.s = d
assert f.o.o.o.o.o.o.o.txt == "k"