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

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

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

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

l = A("l")
k = B("k")
d = C("d")
c = D("c")

l.r = c
l.s = d
k.r = d
k.y = d
k.p = l
k.q = c
d.s = k
d.v = l
c.t = d
assert k.q.t.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.s: C = None
        self.txt = txt

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

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

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

l = A("l")
k = B("k")
d = C("d")
c = D("c")

l.r = c
l.s = d
k.r = d
k.y = d
k.p = l
k.q = c
d.s = k
d.v = l
c.t = d
assert k.q.t.v.r.txt == "c"