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

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

b = A("b")
j = B("j")
l = A("l")
n = B("n")
d = A("d")
f = B("f")

b.o = f
j.r = n
j.q = b
l.o = f
n.r = f
n.q = l
d.o = j
f.r = j
f.q = l
assert b.o.q.o.r.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

b = A("b")
j = B("j")
l = A("l")
n = B("n")
d = A("d")
f = B("f")

b.o = f
j.r = n
j.q = b
l.o = f
n.r = f
n.q = l
d.o = j
f.r = j
f.q = l
assert b.o.q.o.r.r.q.txt == "l"