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

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

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

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

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

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

g.p = b
h.r = k
h.w = f
k.p = b
m.r = g
m.w = k
j.r = f
j.w = f
f.p = b
b.r = f
b.w = k
assert g.p.r.p.w.p.txt == "b"