class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: B = None
        self.w: D = None
        self.p: C = None
        self.q: C = None
        self.txt = txt

f = A("f")
n = B("n")
i = C("i")
c = D("c")
g = E("g")

f.t = c
n.v = g
i.t = f
c.z = i
c.w = i
c.r = f
g.y = i
g.p = i
g.q = i
g.z = n
g.w = c
assert c.w.t.t.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: B = None
        self.w: D = None
        self.p: C = None
        self.q: C = None
        self.txt = txt

f = A("f")
n = B("n")
i = C("i")
c = D("c")
g = E("g")

f.t = c
n.v = g
i.t = f
c.z = i
c.w = i
c.r = f
g.y = i
g.p = i
g.q = i
g.z = n
g.w = c
assert c.w.t.t.w.t.txt == "f"