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

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

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

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

c = A("c")
i = B("i")
a = C("a")
j = D("j")
d = A("d")
h = B("h")
b = C("b")

c.q = h
c.r = j
c.p = a
i.z = b
i.w = d
i.r = h
a.z = d
a.y = b
a.r = b
a.v = c
j.r = h
j.o = c
j.t = c
j.p = a
d.q = h
d.r = j
d.p = b
h.z = b
h.w = d
h.r = i
b.z = d
b.v = d
b.y = a
b.r = a
assert b.y.v.r.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: D = None
        self.p: C = None
        self.txt = txt

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

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

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

c = A("c")
i = B("i")
a = C("a")
j = D("j")
d = A("d")
h = B("h")
b = C("b")

c.q = h
c.r = j
c.p = a
i.z = b
i.w = d
i.r = h
a.z = d
a.y = b
a.r = b
a.v = c
j.r = h
j.o = c
j.t = c
j.p = a
d.q = h
d.r = j
d.p = b
h.z = b
h.w = d
h.r = i
b.z = d
b.v = d
b.y = a
b.r = a
assert b.y.v.r.p.z.p.txt == "b"