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.p: A = None
        self.txt = txt

c = A("c")
k = B("k")
a = B("a")
d = A("d")
j = A("j")
i = B("i")
f = B("f")
g = B("g")

c.r = f
c.w = j
k.p = j
a.p = c
d.r = a
d.w = c
j.r = a
j.w = c
i.p = d
f.p = d
g.p = c
assert f.p.w.r.p.r.p.r.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.p: A = None
        self.txt = txt

c = A("c")
k = B("k")
a = B("a")
d = A("d")
j = A("j")
i = B("i")
f = B("f")
g = B("g")

c.r = f
c.w = j
k.p = j
a.p = c
d.r = a
d.w = c
j.r = a
j.w = c
i.p = d
f.p = d
g.p = c
assert f.p.w.r.p.r.p.r.txt == "f"