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

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

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

c = A("c")
g = B("g")
d = C("d")
h = A("h")
e = A("e")

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

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

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

c = A("c")
g = B("g")
d = C("d")
h = A("h")
e = A("e")

c.z = h
c.v = h
c.w = h
g.r = e
g.u = h
g.v = d
d.u = g
h.z = c
h.v = c
h.w = c
e.z = c
e.w = c
e.v = h
assert g.r.w.z.z.v.txt == "h"