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

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

class C:
    def __init__(self, txt: str):
        self.u: C = None
        self.p: C = None
        self.txt = txt

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

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

g.q = i
n.r = g
n.y = g
n.x = i
n.u = f
f.u = i
f.p = i
l.s = n
l.r = g
l.x = i
l.w = i
i.u = f
i.p = f
assert f.p.p.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: C = None
        self.p: C = None
        self.txt = txt

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

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

g.q = i
n.r = g
n.y = g
n.x = i
n.u = f
f.u = i
f.p = i
l.s = n
l.r = g
l.x = i
l.w = i
i.u = f
i.p = f
assert f.p.p.p.u.txt == "f"