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

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

j = A("j")
m = B("m")
h = B("h")
g = A("g")
d = A("d")
f = B("f")
n = B("n")

j.r = g
m.w = h
m.o = d
h.w = n
h.o = d
g.r = j
d.r = g
f.w = h
f.o = d
n.w = m
n.o = g
assert f.o.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

j = A("j")
m = B("m")
h = B("h")
g = A("g")
d = A("d")
f = B("f")
n = B("n")

j.r = g
m.w = h
m.o = d
h.w = n
h.o = d
g.r = j
d.r = g
f.w = h
f.o = d
n.w = m
n.o = g
assert f.o.r.r.r.txt == "g"