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

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

i = A("i")
j = B("j")
a = B("a")
f = A("f")
h = A("h")
k = B("k")

i.z = f
i.x = h
j.q = f
j.v = f
a.q = f
a.v = i
f.z = h
f.x = i
h.z = i
h.x = i
k.q = f
k.v = f
assert k.v.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: A = None
        self.txt = txt

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

i = A("i")
j = B("j")
a = B("a")
f = A("f")
h = A("h")
k = B("k")

i.z = f
i.x = h
j.q = f
j.v = f
a.q = f
a.v = i
f.z = h
f.x = i
h.z = i
h.x = i
k.q = f
k.v = f
assert k.v.z.x.z.txt == "f"