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

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

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

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

g = A("g")
c = B("c")
d = C("d")
k = D("k")
l = C("l")
f = B("f")
n = A("n")
j = D("j")

g.t = f
g.x = n
g.r = l
g.q = l
c.p = j
c.z = f
c.x = k
d.z = g
k.z = d
k.x = n
l.z = n
f.p = k
f.z = c
f.x = j
n.t = c
n.x = g
n.r = d
n.q = l
j.z = l
j.x = g
assert f.x.x.x.q.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: A = None
        self.r: C = None
        self.q: C = None
        self.txt = txt

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

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

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

g = A("g")
c = B("c")
d = C("d")
k = D("k")
l = C("l")
f = B("f")
n = A("n")
j = D("j")

g.t = f
g.x = n
g.r = l
g.q = l
c.p = j
c.z = f
c.x = k
d.z = g
k.z = d
k.x = n
l.z = n
f.p = k
f.z = c
f.x = j
n.t = c
n.x = g
n.r = d
n.q = l
j.z = l
j.x = g
assert f.x.x.x.q.z.r.txt == "d"