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

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

l = A("l")
i = B("i")
g = B("g")
d = B("d")
e = B("e")
b = B("b")
c = A("c")
f = A("f")

l.r = d
i.q = f
g.q = l
d.q = c
e.q = c
b.q = f
c.r = g
f.r = b
assert l.r.q.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

l = A("l")
i = B("i")
g = B("g")
d = B("d")
e = B("e")
b = B("b")
c = A("c")
f = A("f")

l.r = d
i.q = f
g.q = l
d.q = c
e.q = c
b.q = f
c.r = g
f.r = b
assert l.r.q.r.q.r.txt == "d"