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

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

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

h = A("h")
i = B("i")
c = C("c")
g = C("g")

h.v = i
h.w = i
i.v = c
c.t = h
c.v = h
c.x = g
g.t = h
g.v = h
g.x = c
assert g.v.w.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.w: B = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
c = C("c")
g = C("g")

h.v = i
h.w = i
i.v = c
c.t = h
c.v = h
c.x = g
g.t = h
g.v = h
g.x = c
assert g.v.w.v.x.txt == "g"