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

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

j = A("j")
l = B("l")
d = B("d")
i = B("i")
g = B("g")
m = A("m")
a = A("a")

j.t = a
j.s = m
l.s = i
l.r = d
d.s = l
d.r = l
i.s = d
i.r = g
g.s = l
g.r = i
m.t = a
m.s = a
a.t = j
a.s = j
assert d.r.r.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.s: A = None
        self.txt = txt

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

j = A("j")
l = B("l")
d = B("d")
i = B("i")
g = B("g")
m = A("m")
a = A("a")

j.t = a
j.s = m
l.s = i
l.r = d
d.s = l
d.r = l
i.s = d
i.r = g
g.s = l
g.r = i
m.t = a
m.s = a
a.t = j
a.s = j
assert d.r.r.s.s.s.s.txt == "l"