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

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

e = A("e")
g = B("g")
f = A("f")
a = A("a")
l = A("l")
i = B("i")

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

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

e = A("e")
g = B("g")
f = A("f")
a = A("a")
l = A("l")
i = B("i")

e.r = a
e.y = i
g.q = a
g.x = i
f.r = a
f.y = i
a.r = l
a.y = i
l.r = e
l.y = g
i.q = e
i.x = g
assert l.r.r.r.txt == "l"