class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.z: D = None
        self.p: B = None
        self.s: B = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
g = C("g")
j = D("j")
c = B("c")
h = C("h")

a.u = h
a.z = j
a.p = f
a.s = c
f.x = h
f.q = g
f.p = c
f.r = j
g.x = c
j.p = f
j.r = g
j.w = c
j.x = a
c.x = g
c.q = g
c.p = f
c.r = j
h.x = f
assert f.q.x.r.x.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.z: D = None
        self.p: B = None
        self.s: B = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
g = C("g")
j = D("j")
c = B("c")
h = C("h")

a.u = h
a.z = j
a.p = f
a.s = c
f.x = h
f.q = g
f.p = c
f.r = j
g.x = c
j.p = f
j.r = g
j.w = c
j.x = a
c.x = g
c.q = g
c.p = f
c.r = j
h.x = f
assert f.q.x.r.x.z.r.txt == "g"