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

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

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

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

f = A("f")
g = B("g")
a = C("a")
j = D("j")
e = B("e")
c = A("c")
d = B("d")

f.p = j
f.t = d
f.q = g
g.w = f
a.s = c
a.y = c
j.o = f
e.w = f
c.p = j
c.t = d
c.q = g
d.w = f
assert g.w.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.t: B = None
        self.q: B = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
a = C("a")
j = D("j")
e = B("e")
c = A("c")
d = B("d")

f.p = j
f.t = d
f.q = g
g.w = f
a.s = c
a.y = c
j.o = f
e.w = f
c.p = j
c.t = d
c.q = g
d.w = f
assert g.w.t.w.txt == "f"