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

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

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

i = A("i")
d = B("d")
m = C("m")
a = B("a")
f = B("f")

i.v = m
i.q = m
i.p = d
d.u = a
m.r = d
a.u = d
f.u = a
assert i.p.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.q: C = None
        self.p: B = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
m = C("m")
a = B("a")
f = B("f")

i.v = m
i.q = m
i.p = d
d.u = a
m.r = d
a.u = d
f.u = a
assert i.p.u.u.txt == "d"