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

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

e = A("e")
g = B("g")
m = A("m")
c = A("c")
l = B("l")

e.r = g
e.y = l
g.x = l
g.r = l
m.r = l
m.y = l
c.r = g
c.y = g
l.x = g
l.r = g
assert l.r.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: B = None
        self.txt = txt

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

e = A("e")
g = B("g")
m = A("m")
c = A("c")
l = B("l")

e.r = g
e.y = l
g.x = l
g.r = l
m.r = l
m.y = l
c.r = g
c.y = g
l.x = g
l.r = g
assert l.r.r.r.x.txt == "l"