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

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

b = A("b")
a = B("a")
l = A("l")
f = A("f")
c = B("c")
m = A("m")

b.r = a
b.q = m
a.o = m
a.v = f
l.r = c
l.q = b
f.r = a
f.q = b
c.o = b
c.v = f
m.r = a
m.q = f
assert f.r.o.r.o.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
l = A("l")
f = A("f")
c = B("c")
m = A("m")

b.r = a
b.q = m
a.o = m
a.v = f
l.r = c
l.q = b
f.r = a
f.q = b
c.o = b
c.v = f
m.r = a
m.q = f
assert f.r.o.r.o.q.r.txt == "a"