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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: B = None
        self.r: D = None
        self.s: A = None
        self.p: B = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
i = C("i")
d = D("d")
g = E("g")

h.r = i
f.v = i
f.t = i
i.q = f
i.z = f
i.p = f
i.r = d
i.s = h
d.z = f
g.v = i
g.p = h
assert i.q.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: B = None
        self.r: D = None
        self.s: A = None
        self.p: B = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
i = C("i")
d = D("d")
g = E("g")

h.r = i
f.v = i
f.t = i
i.q = f
i.z = f
i.p = f
i.r = d
i.s = h
d.z = f
g.v = i
g.p = h
assert i.q.t.p.t.txt == "i"