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

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

b = A("b")
a = B("a")
h = B("h")
g = B("g")
i = A("i")
f = B("f")
c = A("c")

b.q = i
b.o = c
a.s = h
h.s = g
g.s = f
i.q = c
i.o = c
f.s = a
c.q = i
c.o = b
assert f.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
h = B("h")
g = B("g")
i = A("i")
f = B("f")
c = A("c")

b.q = i
b.o = c
a.s = h
h.s = g
g.s = f
i.q = c
i.o = c
f.s = a
c.q = i
c.o = b
assert f.s.s.s.s.txt == "f"