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

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

f = A("f")
b = B("b")
d = A("d")
h = B("h")
m = A("m")
l = B("l")
g = B("g")

f.q = m
b.o = d
d.q = f
h.o = d
m.q = f
l.o = d
g.o = f
assert g.o.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

f = A("f")
b = B("b")
d = A("d")
h = B("h")
m = A("m")
l = B("l")
g = B("g")

f.q = m
b.o = d
d.q = f
h.o = d
m.q = f
l.o = d
g.o = f
assert g.o.q.q.q.q.q.txt == "m"