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

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

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

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

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

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

c.q = h
c.s = g
f.o = d
i.q = h
i.s = c
m.o = f
d.o = m
h.o = m
g.q = h
g.s = i
k.o = d
assert h.o.o.o.o.o.txt == "f"