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

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

i = A("i")
h = B("h")
j = A("j")
d = B("d")
c = B("c")
a = A("a")
f = A("f")

i.q = a
h.z = c
h.y = f
j.q = f
d.z = h
d.y = a
c.z = h
c.y = j
a.q = f
f.q = i
assert j.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

i = A("i")
h = B("h")
j = A("j")
d = B("d")
c = B("c")
a = A("a")
f = A("f")

i.q = a
h.z = c
h.y = f
j.q = f
d.z = h
d.y = a
c.z = h
c.y = j
a.q = f
f.q = i
assert j.q.q.q.txt == "a"