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

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

h = A("h")
g = B("g")
i = A("i")
f = B("f")

h.v = i
h.p = i
g.q = i
i.v = h
i.p = h
f.q = i
assert i.v.p.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.p: A = None
        self.txt = txt

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

h = A("h")
g = B("g")
i = A("i")
f = B("f")

h.v = i
h.p = i
g.q = i
i.v = h
i.p = h
f.q = i
assert i.v.p.p.v.txt == "i"