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

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

c = A("c")
h = B("h")
j = A("j")
g = A("g")
l = B("l")
a = A("a")
e = A("e")

c.r = h
c.s = h
h.x = g
j.r = l
j.s = l
g.r = l
g.s = l
l.x = a
a.r = l
a.s = l
e.r = h
e.s = h
assert g.r.x.s.x.s.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.s: B = None
        self.txt = txt

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

c = A("c")
h = B("h")
j = A("j")
g = A("g")
l = B("l")
a = A("a")
e = A("e")

c.r = h
c.s = h
h.x = g
j.r = l
j.s = l
g.r = l
g.s = l
l.x = a
a.r = l
a.s = l
e.r = h
e.s = h
assert g.r.x.s.x.s.x.r.txt == "l"