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

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

class C:
    def __init__(self, txt: str):
        self.u: C = None
        self.s: A = None
        self.y: A = None
        self.txt = txt

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

f = A("f")
a = B("a")
c = C("c")
i = D("i")
b = B("b")
n = D("n")
d = C("d")
l = C("l")

f.y = b
a.q = n
a.z = n
a.w = f
c.u = d
c.s = f
c.y = f
i.q = n
b.q = n
b.z = i
b.w = f
n.q = i
d.u = l
d.s = f
d.y = f
l.u = c
l.s = f
l.y = f
assert f.y.z.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: C = None
        self.s: A = None
        self.y: A = None
        self.txt = txt

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

f = A("f")
a = B("a")
c = C("c")
i = D("i")
b = B("b")
n = D("n")
d = C("d")
l = C("l")

f.y = b
a.q = n
a.z = n
a.w = f
c.u = d
c.s = f
c.y = f
i.q = n
b.q = n
b.z = i
b.w = f
n.q = i
d.u = l
d.s = f
d.y = f
l.u = c
l.s = f
l.y = f
assert f.y.z.q.q.q.q.q.txt == "n"