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

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

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

h = A("h")
b = B("b")
d = C("d")
m = A("m")
g = C("g")
n = C("n")

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

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

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

h = A("h")
b = B("b")
d = C("d")
m = A("m")
g = C("g")
n = C("n")

h.r = m
h.v = m
h.p = b
b.p = m
b.o = d
d.r = b
d.w = g
m.r = h
m.v = h
m.p = b
g.r = b
g.w = d
n.r = b
n.w = g
assert h.p.p.p.txt == "b"