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

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

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

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

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

j.z = k
j.o = m
b.v = j
b.w = m
b.x = g
b.p = g
m.q = g
m.r = g
i.y = b
k.q = j
k.r = g
g.z = k
g.o = m
assert k.r.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.o: C = None
        self.txt = txt

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

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

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

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

j.z = k
j.o = m
b.v = j
b.w = m
b.x = g
b.p = g
m.q = g
m.r = g
i.y = b
k.q = j
k.r = g
g.z = k
g.o = m
assert k.r.z.q.z.txt == "k"