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

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

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

j = A("j")
k = B("k")
m = C("m")
c = C("c")
b = B("b")
d = B("d")
l = A("l")
i = C("i")
g = C("g")

j.r = g
j.p = g
j.v = i
k.v = j
k.w = c
m.r = j
c.r = j
b.v = l
b.w = i
d.v = j
d.w = m
l.r = i
l.p = g
l.v = m
i.r = l
g.r = j
assert i.r.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: C = None
        self.v: C = None
        self.txt = txt

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

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

j = A("j")
k = B("k")
m = C("m")
c = C("c")
b = B("b")
d = B("d")
l = A("l")
i = C("i")
g = C("g")

j.r = g
j.p = g
j.v = i
k.v = j
k.w = c
m.r = j
c.r = j
b.v = l
b.w = i
d.v = j
d.w = m
l.r = i
l.p = g
l.v = m
i.r = l
g.r = j
assert i.r.p.r.p.txt == "g"