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

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

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

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

g = A("g")
k = B("k")
c = C("c")
l = D("l")
e = A("e")
j = D("j")

g.w = c
k.p = c
k.w = c
c.z = g
c.t = e
l.t = e
e.w = c
j.t = e
assert j.t.w.t.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

g = A("g")
k = B("k")
c = C("c")
l = D("l")
e = A("e")
j = D("j")

g.w = c
k.p = c
k.w = c
c.z = g
c.t = e
l.t = e
e.w = c
j.t = e
assert j.t.w.t.w.t.txt == "e"