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

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

e = A("e")
k = B("k")
g = A("g")
d = B("d")
b = B("b")
f = A("f")
n = A("n")
c = A("c")
i = A("i")
h = B("h")

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

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

e = A("e")
k = B("k")
g = A("g")
d = B("d")
b = B("b")
f = A("f")
n = A("n")
c = A("c")
i = A("i")
h = B("h")

e.w = k
k.p = b
k.r = n
g.w = k
d.p = h
d.r = n
b.p = k
b.r = e
f.w = h
n.w = d
c.w = h
i.w = d
h.p = d
h.r = f
assert i.w.p.r.txt == "f"