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

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

k = A("k")
e = B("e")
c = B("c")
m = B("m")
n = B("n")
h = B("h")
b = A("b")

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

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

k = A("k")
e = B("e")
c = B("c")
m = B("m")
n = B("n")
h = B("h")
b = A("b")

k.p = b
k.w = h
e.r = k
e.v = k
c.r = k
c.v = b
m.r = b
m.v = k
n.r = k
n.v = b
h.r = k
h.v = k
b.p = k
b.w = m
assert h.v.p.p.txt == "k"