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

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

k = A("k")
h = B("h")
b = A("b")
a = A("a")
n = B("n")
f = B("f")
g = A("g")

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

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

k = A("k")
h = B("h")
b = A("b")
a = A("a")
n = B("n")
f = B("f")
g = A("g")

k.r = h
k.w = g
h.o = a
b.r = h
b.w = a
a.r = h
a.w = b
n.o = a
f.o = k
g.r = n
g.w = b
assert h.o.r.o.w.txt == "b"