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

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

g = A("g")
b = B("b")
d = A("d")
c = B("c")
k = A("k")
m = B("m")
h = B("h")
n = B("n")

g.x = m
b.x = d
b.v = d
d.x = h
c.x = g
c.v = g
k.x = n
m.x = g
m.v = d
h.x = g
h.v = k
n.x = g
n.v = d
assert k.x.x.x.v.x.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

g = A("g")
b = B("b")
d = A("d")
c = B("c")
k = A("k")
m = B("m")
h = B("h")
n = B("n")

g.x = m
b.x = d
b.v = d
d.x = h
c.x = g
c.v = g
k.x = n
m.x = g
m.v = d
h.x = g
h.v = k
n.x = g
n.v = d
assert k.x.x.x.v.x.v.x.v.txt == "d"