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

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

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

i.s = b
k.o = d
k.q = b
a.s = m
b.s = i
m.s = b
f.o = k
f.q = m
d.o = k
d.q = a
l.o = k
l.q = a
assert f.o.q.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: B = None
        self.q: A = None
        self.txt = txt

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

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