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

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

l = A("l")
e = B("e")
n = B("n")
m = B("m")
d = B("d")
c = A("c")
g = B("g")
a = B("a")

l.u = c
l.r = c
e.s = g
n.s = e
m.s = d
d.s = m
c.u = l
c.r = l
g.s = a
a.s = d
assert e.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.r: A = None
        self.txt = txt

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

l = A("l")
e = B("e")
n = B("n")
m = B("m")
d = B("d")
c = A("c")
g = B("g")
a = B("a")

l.u = c
l.r = c
e.s = g
n.s = e
m.s = d
d.s = m
c.u = l
c.r = l
g.s = a
a.s = d
assert e.s.s.s.txt == "d"