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

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

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

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

l = A("l")
j = B("j")
g = C("g")
e = D("e")
h = A("h")

l.q = g
l.p = h
j.y = g
g.t = j
e.x = l
e.w = j
e.z = g
e.q = g
h.q = g
h.p = l
assert j.y.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: A = None
        self.txt = txt

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

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

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

l = A("l")
j = B("j")
g = C("g")
e = D("e")
h = A("h")

l.q = g
l.p = h
j.y = g
g.t = j
e.x = l
e.w = j
e.z = g
e.q = g
h.q = g
h.p = l
assert j.y.t.y.txt == "g"