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

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

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

d = A("d")
j = B("j")
g = C("g")
h = B("h")
c = C("c")
b = B("b")

d.r = j
j.v = h
j.u = b
j.r = g
g.u = j
g.z = d
g.p = b
h.v = j
h.u = j
h.r = c
c.u = h
c.p = h
c.z = d
b.v = h
b.u = j
b.r = c
assert d.r.v.v.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
g = C("g")
h = B("h")
c = C("c")
b = B("b")

d.r = j
j.v = h
j.u = b
j.r = g
g.u = j
g.z = d
g.p = b
h.v = j
h.u = j
h.r = c
c.u = h
c.p = h
c.z = d
b.v = h
b.u = j
b.r = c
assert d.r.v.v.r.p.r.txt == "c"