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

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

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

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

a = A("a")
g = B("g")
k = C("k")
e = D("e")
j = A("j")
i = D("i")
d = D("d")
n = C("n")

a.r = n
a.s = i
g.v = n
k.q = n
k.r = j
e.r = i
j.r = k
j.s = d
i.r = d
d.r = i
n.q = k
n.r = a
assert d.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: D = None
        self.txt = txt

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

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

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

a = A("a")
g = B("g")
k = C("k")
e = D("e")
j = A("j")
i = D("i")
d = D("d")
n = C("n")

a.r = n
a.s = i
g.v = n
k.q = n
k.r = j
e.r = i
j.r = k
j.s = d
i.r = d
d.r = i
n.q = k
n.r = a
assert d.r.r.r.txt == "i"