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

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

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

c = A("c")
b = B("b")
g = C("g")
m = C("m")
f = A("f")
e = C("e")
d = B("d")

c.r = g
c.t = b
c.v = f
b.q = g
b.r = g
b.p = c
g.p = d
m.p = b
f.r = g
f.t = d
f.v = c
e.p = b
d.q = m
d.r = g
d.p = f
assert d.q.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: B = None
        self.v: A = None
        self.txt = txt

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

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

c = A("c")
b = B("b")
g = C("g")
m = C("m")
f = A("f")
e = C("e")
d = B("d")

c.r = g
c.t = b
c.v = f
b.q = g
b.r = g
b.p = c
g.p = d
m.p = b
f.r = g
f.t = d
f.v = c
e.p = b
d.q = m
d.r = g
d.p = f
assert d.q.p.r.p.txt == "d"