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

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

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

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

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

c = A("c")
a = B("a")
b = C("b")
d = D("d")
j = E("j")
h = B("h")
f = D("f")
g = E("g")
e = B("e")

c.r = h
c.x = h
c.w = b
c.p = g
c.t = d
a.p = d
b.t = j
b.x = j
d.t = f
j.z = b
j.p = b
j.q = g
j.y = h
h.p = f
f.t = d
g.z = b
g.p = b
g.q = j
g.y = a
e.p = f
assert f.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: C = None
        self.p: E = None
        self.t: D = None
        self.x: B = None
        self.txt = txt

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

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

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

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

c = A("c")
a = B("a")
b = C("b")
d = D("d")
j = E("j")
h = B("h")
f = D("f")
g = E("g")
e = B("e")

c.r = h
c.x = h
c.w = b
c.p = g
c.t = d
a.p = d
b.t = j
b.x = j
d.t = f
j.z = b
j.p = b
j.q = g
j.y = h
h.p = f
f.t = d
g.z = b
g.p = b
g.q = j
g.y = a
e.p = f
assert f.t.t.t.t.t.t.txt == "f"