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

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

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

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

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

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

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

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

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

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

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