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

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

m = A("m")
b = B("b")
e = B("e")
h = B("h")
a = B("a")
k = A("k")
l = B("l")
f = A("f")
d = B("d")

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

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

m = A("m")
b = B("b")
e = B("e")
h = B("h")
a = B("a")
k = A("k")
l = B("l")
f = A("f")
d = B("d")

m.o = d
m.q = f
b.q = k
e.q = m
h.q = f
a.q = f
k.o = a
k.q = f
l.q = f
f.o = d
f.q = k
d.q = k
assert d.q.o.q.o.q.q.txt == "f"