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

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

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

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

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

j.s = d
j.z = l
j.q = c
g.x = l
c.r = g
c.s = j
k.q = j
d.q = j
l.x = g
h.x = g
assert h.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.z: B = None
        self.q: C = None
        self.txt = txt

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

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

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

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

j.s = d
j.z = l
j.q = c
g.x = l
c.r = g
c.s = j
k.q = j
d.q = j
l.x = g
h.x = g
assert h.x.x.x.txt == "g"