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

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

class C:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: D = None
        self.v: B = None
        self.x: D = None
        self.txt = txt

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

b = A("b")
j = B("j")
g = C("g")
m = D("m")
n = B("n")
c = C("c")
k = A("k")

b.t = k
j.q = m
j.z = n
g.y = b
g.q = m
g.x = m
g.v = j
m.y = c
m.t = j
m.p = g
n.q = m
n.z = j
c.y = b
c.q = m
c.x = m
c.v = n
k.t = b
assert g.q.y.q.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: D = None
        self.v: B = None
        self.x: D = None
        self.txt = txt

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

b = A("b")
j = B("j")
g = C("g")
m = D("m")
n = B("n")
c = C("c")
k = A("k")

b.t = k
j.q = m
j.z = n
g.y = b
g.q = m
g.x = m
g.v = j
m.y = c
m.t = j
m.p = g
n.q = m
n.z = j
c.y = b
c.q = m
c.x = m
c.v = n
k.t = b
assert g.q.y.q.p.v.txt == "j"