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

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

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

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

k = A("k")
h = B("h")
j = C("j")
a = D("a")
g = C("g")

k.z = h
k.q = h
h.r = k
j.r = g
a.r = h
a.v = h
a.y = j
g.r = j
assert a.y.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: B = None
        self.txt = txt

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

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

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

k = A("k")
h = B("h")
j = C("j")
a = D("a")
g = C("g")

k.z = h
k.q = h
h.r = k
j.r = g
a.r = h
a.v = h
a.y = j
g.r = j
assert a.y.r.r.r.txt == "g"