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

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

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

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

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

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

l.r = g
l.o = g
i.s = l
m.s = c
e.s = d
c.r = d
c.o = j
d.r = g
d.o = g
j.r = c
j.o = d
f.s = l
g.r = d
g.o = j
b.s = l
assert j.o.r.o.txt == "j"