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

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

n = A("n")
b = B("b")
f = A("f")
h = A("h")
k = A("k")
i = B("i")
m = A("m")
j = B("j")

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

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

n = A("n")
b = B("b")
f = A("f")
h = A("h")
k = A("k")
i = B("i")
m = A("m")
j = B("j")

n.w = b
b.o = i
b.r = j
f.w = i
h.w = b
k.w = i
i.o = j
i.r = j
m.w = i
j.o = b
j.r = i
assert i.o.r.o.txt == "j"