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

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

i = A("i")
d = B("d")
j = B("j")
g = B("g")
k = B("k")
h = A("h")
f = B("f")

i.z = j
i.w = f
d.x = h
d.p = k
j.x = i
j.p = d
g.x = h
g.p = f
k.x = h
k.p = d
h.z = g
h.w = k
f.x = h
f.p = j
assert g.x.w.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
j = B("j")
g = B("g")
k = B("k")
h = A("h")
f = B("f")

i.z = j
i.w = f
d.x = h
d.p = k
j.x = i
j.p = d
g.x = h
g.p = f
k.x = h
k.p = d
h.z = g
h.w = k
f.x = h
f.p = j
assert g.x.w.p.x.txt == "h"