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

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

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

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

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

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

k.r = e
k.w = e
f.x = b
g.x = n
b.x = f
a.r = g
a.w = e
n.x = f
d.r = b
d.w = f
e.x = f
assert a.r.x.x.x.txt == "b"