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

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

b = A("b")
f = B("f")
e = B("e")
m = B("m")
n = A("n")
i = A("i")
g = B("g")
j = B("j")

b.s = m
b.y = m
f.r = j
e.r = f
m.r = j
n.s = f
n.y = g
i.s = f
i.y = f
g.r = m
j.r = g
assert n.y.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.txt = txt

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

b = A("b")
f = B("f")
e = B("e")
m = B("m")
n = A("n")
i = A("i")
g = B("g")
j = B("j")

b.s = m
b.y = m
f.r = j
e.r = f
m.r = j
n.s = f
n.y = g
i.s = f
i.y = f
g.r = m
j.r = g
assert n.y.r.r.r.r.txt == "m"