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

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

i = A("i")
k = B("k")
f = B("f")
a = A("a")
b = A("b")

i.o = a
k.t = a
k.s = i
f.t = a
f.s = i
a.o = i
b.o = a
assert k.s.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.t: A = None
        self.s: A = None
        self.txt = txt

i = A("i")
k = B("k")
f = B("f")
a = A("a")
b = A("b")

i.o = a
k.t = a
k.s = i
f.t = a
f.s = i
a.o = i
b.o = a
assert k.s.o.o.o.o.txt == "i"