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

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

f = A("f")
n = B("n")
h = B("h")
i = A("i")
e = A("e")
j = A("j")

f.q = i
n.x = f
n.v = h
h.x = f
h.v = n
i.q = j
e.q = i
j.q = i
assert h.v.v.x.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.x: A = None
        self.v: B = None
        self.txt = txt

f = A("f")
n = B("n")
h = B("h")
i = A("i")
e = A("e")
j = A("j")

f.q = i
n.x = f
n.v = h
h.x = f
h.v = n
i.q = j
e.q = i
j.q = i
assert h.v.v.x.q.q.q.txt == "i"