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

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

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

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

f = A("f")
n = B("n")
j = C("j")
a = D("a")
e = A("e")
g = A("g")

f.y = n
n.y = a
j.w = n
a.x = n
a.t = n
a.r = n
a.y = j
e.y = n
g.y = n
assert j.w.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

f = A("f")
n = B("n")
j = C("j")
a = D("a")
e = A("e")
g = A("g")

f.y = n
n.y = a
j.w = n
a.x = n
a.t = n
a.r = n
a.y = j
e.y = n
g.y = n
assert j.w.y.r.y.txt == "a"