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

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

h = A("h")
j = B("j")
b = B("b")
l = B("l")
g = A("g")
c = A("c")
k = B("k")
f = B("f")

h.p = c
j.v = c
b.v = g
l.v = g
g.p = h
c.p = h
k.v = c
f.v = g
assert g.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

h = A("h")
j = B("j")
b = B("b")
l = B("l")
g = A("g")
c = A("c")
k = B("k")
f = B("f")

h.p = c
j.v = c
b.v = g
l.v = g
g.p = h
c.p = h
k.v = c
f.v = g
assert g.p.p.p.p.txt == "c"