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

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

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

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

h = A("h")
j = B("j")
l = C("l")
f = D("f")
k = A("k")

h.r = k
h.q = l
j.t = l
j.s = k
l.r = j
l.q = j
f.z = k
k.r = h
k.q = l
assert k.r.q.r.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: C = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
l = C("l")
f = D("f")
k = A("k")

h.r = k
h.q = l
j.t = l
j.s = k
l.r = j
l.q = j
f.z = k
k.r = h
k.q = l
assert k.r.q.r.s.q.txt == "l"