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

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

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

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

f = A("f")
g = B("g")
m = C("m")
i = D("i")
h = A("h")

f.q = h
f.y = g
g.q = f
g.p = i
g.x = i
m.r = f
i.q = f
i.y = f
i.t = f
h.q = f
h.y = g
assert g.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.y: B = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
m = C("m")
i = D("i")
h = A("h")

f.q = h
f.y = g
g.q = f
g.p = i
g.x = i
m.r = f
i.q = f
i.y = f
i.t = f
h.q = f
h.y = g
assert g.q.y.q.txt == "f"