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.u: A = None
        self.txt = txt

a = A("a")
f = B("f")
h = A("h")
k = B("k")
i = A("i")
j = B("j")
d = A("d")

a.s = i
f.o = k
f.u = h
h.s = a
k.o = f
k.u = d
i.s = a
j.o = k
j.u = a
d.s = i
assert a.s.s.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.u: A = None
        self.txt = txt

a = A("a")
f = B("f")
h = A("h")
k = B("k")
i = A("i")
j = B("j")
d = A("d")

a.s = i
f.o = k
f.u = h
h.s = a
k.o = f
k.u = d
i.s = a
j.o = k
j.u = a
d.s = i
assert a.s.s.s.txt == "i"