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

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

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

class D:
    def __init__(self, txt: str):
        self.r: E = None
        self.txt = txt

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

b = A("b")
c = B("c")
g = C("g")
d = D("d")
e = E("e")
h = A("h")
i = D("i")

b.x = g
b.z = e
c.x = b
g.w = b
g.v = b
g.y = h
g.r = h
g.u = c
d.r = e
e.t = h
e.x = g
e.p = g
e.r = g
h.x = g
h.z = e
i.r = e
assert g.v.z.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.z: E = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: E = None
        self.txt = txt

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

b = A("b")
c = B("c")
g = C("g")
d = D("d")
e = E("e")
h = A("h")
i = D("i")

b.x = g
b.z = e
c.x = b
g.w = b
g.v = b
g.y = h
g.r = h
g.u = c
d.r = e
e.t = h
e.x = g
e.p = g
e.r = g
h.x = g
h.z = e
i.r = e
assert g.v.z.t.x.txt == "g"