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

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

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

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

e.v = m
m.t = h
m.p = h
f.w = e
b.v = g
g.t = h
g.p = h
h.w = b
assert g.p.w.v.p.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

e.v = m
m.t = h
m.p = h
f.w = e
b.v = g
g.t = h
g.p = h
h.w = b
assert g.p.w.v.p.w.v.txt == "g"